Is there an elegant way (filters, interceptors) to intercept an unmarshalled object (and its annotations) in Jersey before it gets into the web service resource methods - those that are annotated with @POST, @PUT.
I really need the entity itself and any annotations that it has on it, and then test on this object using the validation annotation properties (looks like JSR 303, but we do not annotate the entire bean with metadata). From the point of view of resource implementation, my goal is to be able to simply type this in the resource method:
@Path("/people") @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public class PeopleService { @POST public Response createPerson(@CustomValidator("personValidator") Person person) throws URISyntaxException { String uri = someService.createPerson(person); return Response.created(new URI(uri)).entity(uri).build(); } }
I started the path of writing a custom MessageBodyReader, and I was able to fully run JSON because I was simply delegating ObjectMapper to deserialize JSON. Other than that, I passed parameter annotations and everything works fine. However, when I needed to deserialize XML, everything fell apart. I have no idea how to get the original deserializer that Jersey would use and delegate to him. I also feel that I overwrite the pieces of Jersey unnecessarily and would prefer to stop using MessageBodyReader as a hacking integration point if the jersey has a layer after MessageBodyReader and before the implementation calls the web resource service, which allows it to be extended so that I can add a custom one flow behavior.
Ultimately, does Jersey have any additional points where it can pass me the unmarshalled entity and any of its parameter annotations and allow me to do custom processing? Or do I need to figure out how to create entities myself (using JAXBContext and what not)? Perhaps resorting to AOP? Embed validator in resource class and abandon this annotation idea?
Jersey Version: 1.5
Lo-tan
source share