Alex Rader opened SPR-15830 and commented
@JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
@JsonSubTypes({@JsonSubTypes.Type(Dog.class), @JsonSubTypes.Type(Elephant.class)})
public abstract class Animal {
private String sound;
public String getSound() {
return sound;
}
public void setSound(String sound) {
this.sound = sound;
}
}
@JsonTypeName("dog")
public class Dog extends Animal {
}
@JsonTypeName("elephant")
public class Elephant extends Animal {
}
@Controller
public class MyController {
@RequestMapping(value = "animal")
public @ResponseBody String save(@RequestBody Animal animal) {
System.out.println(animal.getClass());
return success;
}
@RequestMapping(value = "dog")
public @ResponseBody String save(@RequestBody Dog dog) {
System.out.println(dog.getClass());
return success;
}
}
When I send request to /dog
{
"sound": "woof"
}
I get exception
com.fasterxml.jackson.databind.JsonMappingException: Unexpected token (END_OBJECT), expected FIELD_NAME: missing property 'type' that is to contain type id (for class Dog)
When I send "type" filed to /animal, this is ok, but for /dog this is not desired.
No further details from SPR-15830
Comment From: snicoll
The (short) exception that you've shared is from Jackson. I don't really see what you'd expect the core container to do as we rely on Jackson to deserialize the data. If you believe this is a bug in Spring Framework, please share a small sample, and this issue can be reopened for consideration.