I am trying to deserialize a JSON Object into a Java Object using Jackson annotation on one Abstact class "Animal":
@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 a sample JSON string:
{
"name": "Chihuahua",
"type": {
"code": "chien",
"description": "Chien mechant"
}
}
The problem is that the property "type" 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 "property" value but nothing. the Exeption is this
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's wrong. Thank you.