I have the following object model in my Spring MVC (v3.2.0.RELEASE) web application:
public class Order {
private Payment payment;
}
@JsonTypeInfo(use = J
Rashmin's answer worked, and I found an alternative way to avoid the com.fasterxml.jackson.databind.JsonMappingException: Could not resolve type id into a subtype of Blah
issue without needing to use registerSubtypes
. What you can do is add the following annotation to the parent class:
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "type")
Note that the difference is JsonTypeInfo.Id.CLASS
instead of JsonTypeInfo.Id.NAME
. The downside is that the created JSON will contain the entire class name including the full namespace. The upside is that you don't have to worry about registering subtypes.