Hi Charles,
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.
Hth,
Paul.
On Mar 9, 2010, at 5:30 AM, Charles Overbeck wrote:
> Hello,
>
> I have code like this:
>
> ...
> @GET
> @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_JSON})
> public JAXBElement<CurrenciesType> listSupportedCurrencies() {
> CurrencyService currencyService = (CurrencyService)
> getService();
> CurrenciesType currenciesType = getSupportedCurrencies();
> return new ObjectFactory().createCurrencies(currenciesType);
> }
>
> I would like to control whether the response is JSON or XML via a
> query parameter, e.g., /currencies?fmt=json, or /currencies?fmt=xml.
>
> With the above, I know I can control whether the response is JSON or
> XML via the HTTP Accept request header. I also know that I can
> programatically build up a Reponse and return that.
>
> But a client would prefer a query parameter controlling the format,
> as he feels it is more visible and obvious. And I like my method
> signature the way it is now, instead of returning a Response, as it
> is more self-documenting.
>
> Any thoughts or ideas are appreciated.
>
> Thanks,
>
> Charles
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>