Spring @RequestBody containing a list of different types (but same interface)

There is a simpler annotation out now:

@JsonRootName("dog")
public class Dog extends Animal {...}

The reference to the annotation can be found on fasterxml.github


You should use the Jackson annotations @JsonTypeInfo and @JsonSubTypes to achieve polymorphic json. The annotations go on the Animal base class.

@JsonTypeInfo(use = Id.NAME, include = As.PROPERTY, property = "type")
@JsonSubTypes({@JsonSubTypes.Type(value = Dog.class, name = "Dog"),
        @JsonSubTypes.Type(value = Cat.class, name = "Cat")})
public abstract class Animal {

}