我想反序列化一个hashmap,其值是对象的集合/列表。但杰克逊不承认这些物体的类别。
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(createTestData(1, 0));
System.out.println(json);
这给了我:
{
"interval":[
{
"discriminator":"Interval",
"uuid":"298d8bc0-4259-4437-bd03-ffa83b62851c",
}
]
}
现在,我想再次反序列化它:
ObjectMapper objectMapper = new ObjectMapper();
HashMap jsonWrapper = objectMapper.readValue(json, HashMap.class);
但Jackson
将Interval
对象创建为HashMap
。我已将Interval
配置为:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "discriminator")
public class Interval {
....
}