【发布时间】:2012-09-26 20:54:41
【问题描述】:
我正在使用 Jackson,但遇到问题,当我尝试反序列化对象时,我收到以下错误:
com.fasterxml.jackson.databind.JsonMappingException:
Can not construct instance of net.MyAbstractClass,
problem: abstract types either need to be mapped to concrete types,
have custom deserializer, or be instantiated with additional type information
我的属性有问题:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT, property = "@id")
@JsonSubTypes({ @JsonSubTypes.Type(value = MyAbstractClass.class, name = "MyAbstractClass") })
@ManyToOne
private MyAbstractClass object;
谁能帮帮我?
【问题讨论】:
-
另一个类似案例的讨论在stackoverflow.com/a/32777371/873282完成。特别有趣的是使用
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "type")的评论。那样的话,JSON 会大一些,但是很明确,应该使用哪种类型。