Let's say that I have a domain class :
public class Zoo{
private List<Animal> animals;
....
where an Animal is an interface with different implementations (Cat,Dog). Let's say that I want to be able to save a Zoo object :
@RequestMapping(value = "/zoo", method = RequestMethod.POST)
public @ResponseBody void save(@RequestBody Zoo zoo) {
....
and I want to send a json - something like :
{
animals:[
{type:'Cat', whiskers-length:'3'},
{type:'Dog', name:'Fancy'}
]
}
How can I tell spring MVC to map animal to Cat type when type=='Cat' and to map it to a Dog class when type=='Dog'?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…