Suppose Animal is an abstract class in my project, and I have a REST resource (on a JAX-RS server, using Jackson for (de)serialization) for a PUT to manipulate animals that are stored in my database. They have concrete types, and the REST resource specifies the type in the path of the request:
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Path("/{entityType}/{id: \\d+}")
public <T extends Animal> void putAnimal(@PathParam("entityType") String entityType, @PathParam("id") String id, Animal input) throws IOException {
//...
}
I want to use entityType to pick the concrete class to deserialize with (Dog or Cat or whatever, for entityType being dog or cat or whatever). For reasons which are too complicated to explain here, I cannot put the type information in the JSON input itself.
So AIUI annotating Animal with a custom TypeIdResolver or something of the sort can't help me, because the type information won't be in the JSON itself (and that's all the info that the type resolver will get). I was planning to use a custom MessageBodyReader, but as far as I can tell, that doesn't get the other parameter values from the body passed in its readValue method, so I won't know what to deserialize into.
What am I missing? If this approach fails, how can I accomplish what I want without specifying animal-specific endpoints (which leads to lots of duplicate code as well as a loss of generality - right now I can add an subclass of Animal and this code will Just Work, which is very nice.)