Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将具有不同名称的对象列表反序列化到同一pojo_Java_Json_Jackson - Fatal编程技术网

Java 如何将具有不同名称的对象列表反序列化到同一pojo

Java 如何将具有不同名称的对象列表反序列化到同一pojo,java,json,jackson,Java,Json,Jackson,我有以下不同的JSON { "item": [ { "Retailer_Relation": {...}, "Retailer_Relation": {...}, "Retailer_Relation": {...} } ] } 及 下面是我反序列化JSON的类。这显然只适用于第二个JSON。但是,我希望包含Retailer_关系对象的JSON能够与RetailerHolder pojo一起使用 @JsonInclude(JsonIn

我有以下不同的JSON

{
  "item": [
    {
      "Retailer_Relation": {...},
      "Retailer_Relation": {...},
      "Retailer_Relation": {...}
    }
  ]
}

下面是我反序列化JSON的类。这显然只适用于第二个JSON。但是,我希望包含Retailer_关系对象的JSON能够与RetailerHolder pojo一起使用

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class RetailerHolder {
    @JsonProperty("item")
    private List<Retailer> item = new ArrayList<Retailer>();

    public RetailerHolder() {

    }

    public List<Retailer> getItem() {
        return item;
    }

    public void setItem(List<Retailer> item) {
        this.item = item;
    }    
}
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
公共类零售商{
@JsonProperty(“项目”)
私有列表项=新的ArrayList();
公共零售商(){
}
公共列表getItem(){
退货项目;
}
公共无效集合项(列表项){
this.item=项目;
}    
}

有没有办法让Jackson知道我也希望零售商关系被反序列化到零售商pojos中

json文本无效(没有结束数组)Thx,但json仅在本文中无效。我会更新的。在我的环境中,它是有效的。可能这是您的情况是
零售商关系
另一种类型,或者它是否具有与
零售商
相同的属性?@Supahupe它具有完全相同的属性
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class RetailerHolder {
    @JsonProperty("item")
    private List<Retailer> item = new ArrayList<Retailer>();

    public RetailerHolder() {

    }

    public List<Retailer> getItem() {
        return item;
    }

    public void setItem(List<Retailer> item) {
        this.item = item;
    }    
}