I am trying to deserialize a JSON object into a Java object using Jackson's annotation in one Abstact "Animal" class:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") @JsonSubTypes({@Type(value = Dog.class, name = "chien"), @Type(value = Cat.class, name= "chat")})
and here is an example JSON string:
{ "name": "Chihuahua", "type": { "code": "chien", "description": "Chien mechant" } }
The problem is that the "type" property in the JSON object is also an object. when I try to deserialize, I have this exception:
Caused by: org.codehaus.jackson.map.JsonMappingException: Could not resolve type id '{' into a subtype of [simple type, class Animal]
I tried to use "type.code" as a "property", but nothing. Exeption is
Caused by: org.codehaus.jackson.map.JsonMappingException: Unexpected token (END_OBJECT), expected FIELD_NAME: missing property 'type.code' that is to contain type id (for class Animal)
Any idea what is wrong. Thanks.
Jorge source share