Suppose I have three classes.
public abstract class Animal {}
public class Cat extends Animal {}
public class Dog extends Animal {}
Can I do something like this?
Input: a JSON which it is Dog or Cat
Output: a dog/cat depends on input object type
I don't understand why the following code doesn't work. Or should I use two separate methods to handle new dog and cat?
@RequestMapping(value = "/animal", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
private @ResponseBody <T extends Animal>T insertAnimal(@RequestBody T animal) {
return animal;
}
Error message:
HTTP Status 500 - Request processing failed; nested exception is java.lang.IllegalArgumentException: Type variable 'T' can not be resolved