users@jersey.java.net

[Jersey] Re: default media type for jersey

From: Rahul Babbar <rahul.babbar1_at_gmail.com>
Date: Wed, 8 Dec 2010 11:32:41 -0800

Hi,

I had a similar case but i made all the below three calls go to the same
method instead of going to the different methods. A simple wrapper over
Jersey's ServletContainer was written to accomplish the same.

If you are using JAXB for conversion of object to the appropriate formats,
then you only need to return the object and jersey should automatically
convert it to the appropriate format.

However, if you are not using JAXB(as in my case), i convert the object to
the appropriate format and return a String.

Rahul

PS. I am pretty much a beginner in Jersey and the above suggestion has just
been based on my experience.


On Wed, Dec 8, 2010 at 9:22 AM, Rashid Jilani <jilani_at_lifebiosystems.com>wrote:

> Hi: Gurus, I would like to know what would be the default media type in
> jersey if client doesn’t provide one with the client call.
>
>
>
> Second what is the best design pattern to return multiple data format on
> the basis of the client request call.
>
>
>
> E.g lets say I have to return xml, JSON, csv etc formats on the basis of
> the call coming from the client like this
>
>
>
> http://localhost:8084/Rootcontext/resourceName/{id.xm<http://localhost:8084/Rootcontext/resourceName/%7bid.xm>l}
> //Return xml
>
> http://localhost:8084/Rootcontext/resourceName/{id.json}<http://localhost:8084/Rootcontext/resourceName/%7Bid.json%7D>//Return json
>
> http://localhost:8084/Rootcontext/resourceName/{id.csv}<http://localhost:8084/Rootcontext/resourceName/%7Bid.csv%7D> //Return csv
>
>
>
> I am not sure how to call different resource methods that produces
> different data format
>
>
>
> @Produces({MediaType.APPLICATION_JSON})
>
>
>
> @Produces({MediaType.APPLICATION_XML})
>
>
>
> @Produces({MediaType.TEXT_XML})
>
>
>
> Any help would be really appreciated.
>
>
>
> Regards,
>
> RJ
>
>
>
>
>