0

我正在尝试在杰克逊中使用自定义反序列化器来反序列化一些 json 对象。但是,当我尝试让 ObjectMapper 读取 json 时,会发生以下异常:

java.lang.IllegalStateException: AnnotationIntrospector returned Class com.Geometry.GeometryDeserializer; expected Class<JsonDeserializer>

我有点不知所措,因为 AnnotationIntrospector 似乎在抱怨我的 GeometryDeserializer 不是 JsonDeserializer 的子类,而它显然是。

这是我创建对象映射器的地方:

public void deserializeJson(String json) {
    ObjectMapper mapper = new ObjectMapper();
    mapper.addMixInAnnotations(Feature.class, MixIn.class);
    Feature feature = mapper.readValue(json, Feature.class);
}

...我的混音课:

abstract class MixIn {
    @JsonDeserialize(using=GeometryDeserializer.class)
    abstract void setGeometry(Geometry geometry);
}

...和我的反序列化器:

public class GeometryDeserializer extends JsonDeserializer<Geometry> {
    @Override
    public Geometry deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JsonProcessingException {
        //stuff happens
    }
}

任何反馈/帮助将不胜感激。

谢谢。

4

1 回答 1

0

疯狂猜测:您不小心混淆了 Jackson 1.x 和 Jackson 2.x 类型?类名大多相同,但存在于不同的包中——使用一组类时可以正常工作,但 IDE 可能会导致意外混淆。

于 2013-09-20T19:45:13.243 回答