views:

96

answers:

0

In a Rest Service using the JAX-RS specification, I can define a generic service like

@GET
@Path("something")
@Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public List<MyPojo> getMyPojoList() {
    ...
}

Something magic happens in Jersey because when invoking

javax.ws.rs.ext.MessageBodyWriter#writeTo(T t,
        Class<?> type,
        Type genericType,
        Annotation annotations[], 
        MediaType mediaType, 
        MultivaluedMap<String, Object> httpHeaders,
        OutputStream entityStream) throws IOException, WebApplicationException;

when analyzing the genericType it is easy to see that his value is class MyPojo.

I've been trying to read the Jersey source code to understand how they extract the Collection Generic type of before invoking the method writeTo of javax.ws.rs.ext.MessageBodyWriter, but I got lost once arrived to read the GenericEntity class.

Can anyone help me to understand which kind of magic they use there? Thanks in advance!!!