我有一个 JSONObject 类似于:
{
"name": "John",
"details": [
[
"phone",
123456789
],
[
"address",
"abcdef"
]
]
}
我正在尝试将上面的 JSON 映射到以下对象:
@JsonIgnoreProperties(ignoreUnknown = true)
public class Employee{
String name;
List<List<DetailItem>> details;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<List<DetailItem>> getDetails() {
return details;
}
public void setDetails(List<List<DetailItem>> details) {
this.details = details;
}
}
@JsonSubTypes({
@JsonSubTypes.Type(value=String.class),
@JsonSubTypes.Type(value=Integer.class)
})
public class DetailItem{
}
映射使用:
ObjectMapper mapper = new ObjectMapper();
mapper.readValue(instream, Employee.class)
例外:
com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [simple type, DetailItem] from String value; no single-String constructor/factory method (through reference chain: Employe["details"])
我正在尝试按原样进行多态反序列化,DetailItem
或者String
Integer
谢谢