Thursday, 19 September 2013

IllegalStateException occurs when using Jackson @JsonDeserialize annotation

IllegalStateException occurs when using Jackson @JsonDeserialize annotation

I'm trying to use a custom deserializer in Jackson to deserialize some
json objects. However, when I try to have the ObjectMapper read the json,
the following exception occurs:
java.lang.IllegalStateException: AnnotationIntrospector returned Class
com.Geometry.GeometryDeserializer; expected Class<JsonDeserializer>
I'm somewhat at a loss of what to do here, since it seems like the
AnnotationIntrospector is complaining that my GeometryDeserializer is not
a subclass of JsonDeserializer, when it clearly is.
Here's where I create the Object Mapper:
public void deserializeJson(String json) {
ObjectMapper mapper = new ObjectMapper();
mapper.addMixInAnnotations(Feature.class, MixIn.class);
Feature feature = mapper.readValue(json, Feature.class);
}
...my Mix In class:
abstract class MixIn {
@JsonDeserialize(using=GeometryDeserializer.class)
abstract void setGeometry(Geometry geometry);
}
...and my deserializer:
public class GeometryDeserializer extends JsonDeserializer<Geometry> {
@Override
public Geometry deserialize(JsonParser jp, DeserializationContext dc)
throws IOException, JsonProcessingException {
//stuff happens
}
}
Any feedback/assistance would be greatly appriciated.
Thanks.

No comments:

Post a Comment