I\'m using Jackson 1.9.x. Sticking with the Animals example, Here\'s what I\'d like to do:
Let\'s say I have an Animal class:
public class Animal {
I also faced the same issue and found out that the Subtype mapping expects unique classes.
What I did was to create two classes that extend the same base class. The extended classes are empty as they have the same properties as base class. Then added them to the Subtype map. For example, in your case, it will be -
@JsonTypeInfo(use = Id.NAME, include = As.PROPERTY, property = "type")
@JsonSubTypes({@JsonSubTypes.Type(value = Mammal.class, name = "Dog"),
@JsonSubTypes.Type(value = Mammal.class, name = "Cat"),
@JsonSubTypes.Type(value = BirdDodo.class, name = "Dodo"},
@JsonSubTypes.Type(value = BirdCockatoo.class, name = "Cockatoo"})
public class Animal {
}
public class BirdCockatoo extends Cockatoo{}
public class BirdDodo extends Dodo{}
I understand it is the not the best approach but until the issue is not resolved, it could be the best way to fix this. I followed this approach for now.
Hope it helps you!