【发布时间】:2017-11-05 11:20:34
【问题描述】:
我有一个像这样的 json 文件,需要由 Jackson 将其转换为 Java 用户实例。
"userid" : "1",
"myMixes" : [ {
"data" : {
"id" : 1,
"ref": "my-Object-instance"
},
"type" : "object"
}, {
"data" : [ [ 0, 1], [ 1, 2 ] ],
"type" : "list"
}]
我的班级“用户”中有这个:
// jackson should use this, if type="list"
@JsonProperty("data")
public List<List<Integer>> data_list = new ArrayList<>();
// jackson should use this, if type="object"
@JsonProperty("data")
public Data data_object;
@JsonProperty("id")
public String id;
// if type = "object", then jackson should convert json-data-property to Java-Data-Instance
// if type = "list",then jackson should convert json-data-property to List<List<Integer>> data
@JsonProperty("type")
public String type;
如果 json-type-property 的值称为“对象”,我如何告诉 jackson 生成 json-data-property 的 Data-Instance 并生成 List-Instance,如果 json-type- 的值-属性称为“列表”。
【问题讨论】: