tags:

views:

13

answers:

1

In following method:

@GET

@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN})

@Path("{id}")

public String getMessage(@PathParam("username") String username,

    @PathParam("id") int id,
    @QueryParam("format") String format) {

 return "test";
}

how do I return the the data in the specific format determined by the format query parameter.

A: 

I found this suggested solution:

Jersey supports URI-based conneg using a suffix at the end of the path.

You can declare in your web.xml a mapping of suffix to media type:
https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/core/ResourceConfig.html#PROPERTY_MEDIA_TYPE_MAPPINGS

if you want to do the same using a query parameter you could write a
Jersey request filter that does similar things to the suffix filter:

http://fisheye4.atlassian.com/browse/jersey/trunk/jersey/jersey-server/src/main/java/com/sun/jersey/api/container/filter/UriConnegFilter.java?r=HEAD

which modifies the accept header based on the suffix value.

Mads Hansen