users@jersey.java.net

[Jersey] Re: default media type for jersey

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Thu, 9 Dec 2010 10:05:55 +0100

Hi Rashid,

You can achieve this by using URI conneg and map a suffixes to media
types, then you can use the @Produces method.

See:
   http://jersey.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/core/ResourceConfig.html#PROPERTY_MEDIA_TYPE_MAPPINGS

Paul.


On Dec 8, 2010, at 6:22 PM, Rashid Jilani 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.xml} //Return xml
> http://localhost:8084/Rootcontext/resourceName/{id.json} //Return json
> http://localhost:8084/Rootcontext/resourceName/{id.csv} //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
>
>