简体   繁体   中英

Jackson (Java) : deserialization for the same property name but return different objects. for one it return object and second List<Object>

I have a POJO like this:

 public class NewClass {

    String name;
    @JsonProperty("productType")
    ProductType productType2005;
    List<ProductType> productType;
   }

I want to deserialize json into Pojo. The issue is I have property name same productType but I can expect two different return types or data structures.

  1. return ProductType object
  2. return List<ProductType> since property name is the same how can I effectively use Jackson annotations to get it resolved?

I'm using rest-assured for deserialization and Lombok for typical getter and setters.

To my knowledge, this isn't possible. A solution would be to expect a List of ProductType objects with a minimum of at least one if required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM