users@jersey.java.net

[Jersey] MessageBodyReader is used on QueryParam if another annotation comes after QueryParam

From: Jacques <jacques_at_yapmap.com>
Date: Mon, 26 Mar 2012 18:35:18 -0700

I was looking at implementing my own StringReaderProvider for a GET method
consuming JSON. (aka JERSEY-503).

I figured it out but found that I had one problem: it seems like if I put
my custom annotation after @QueryParam in the method parameter definition,
Jersey tries to use a MessageBodyReader to analyze and return the value
rather than a StringReader. Of course, this fails since a GET request
doesn't have a body.

Example 1: Throws an error that no MessageBodyReader exists matching. If I
create one that does match, it throws a EOFException when trying to read
the InputStream in readFrom():

@GET
@Path("/do_stuff")
@Produces({"application/json"})
public Response doStuff(@QueryParam("data") @GetJSON Stuff stuff){

Example 2: Works fine, using the elsewhere defined StringReaderProvider:
@GET
@Path("/do_stuff")
@Produces({"application/json"})
public Response doStuff(@GetJSON @QueryParam("data") Stuff stuff){


I haven't spent time tracing the Jersey code to point to the particular
line number.

This is with the Glassfish 3.1.2 version of Jersey.

Thanks,
Jacques