【发布时间】:2011-09-15 23:07:19
【问题描述】:
我目前正在使用 jackson 1.7 尝试反序列化来自第三方库的对象。
所以我设置我的 ObjectMapper 来使用我的 mixIn 类,如下所示:
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.getDeserializationConfig().addMixInAnnotations(com.vividsolutions.jts.geom.Point.class, MixIn.class);
我的 MixIn 类用 @JsonCreator 注释,并带有实例化 Point 对象的逻辑
public class MixIn {
private static final GeometryFactory geometryFactory = GeometryFactoryFactory.getGeometryFactory();
@JsonCreator
public static Point createPoint(@JsonProperty("x")double x, @JsonProperty("y")double y) {
return geometryFactory.createPoint(new Coordinate(x, y));
}}
但我遇到了异常
No suitable constructor found for type [simple type, class com.vividsolutions.jts.geom.Point]: can not instantiate from JSON object (need to add/enable type information?)
调试显示我的 MixIn 类从未被调用,我认为它需要是具体的类但结果相同。
我做错了什么?我的配置有什么问题?
谢谢
【问题讨论】: