users@glassfish.java.net

Re: how to switch between XML and JSON ?

From: heapifyman <heapifyman_at_gmail.com>
Date: Sat, 3 Jan 2009 17:08:54 +0100

Am 03.01.2009 um 17:07 schrieb Felipe Gaścho:

> humm.. so, If I declare both languages, the client request will define
> which one should be used in the response.. .. interesting.....

If I remember correctly, that's how it works.

>
>
> is there a way to establish a default ? the order ? or other...

I don't know. You'll have to take a look at the Jersey documentation


>
>
> On Sat, Jan 3, 2009 at 4:39 PM, heapifyman <heapifyman_at_gmail.com>
> wrote:
>>
>> The client has to set the ACCEPT header to JSON and only JSON, I
>> suppose.
>>
>> Am 28.12.2008 um 17:41 schrieb Felipe Gaścho:
>>
>>> I have a method annotated to produce both XML or JSON contents..
>>> how
>>> do I switch between them ? what is the URL suffix I must add to my
>>> resource URL ??
>>>
>>> For example:
>>>
>>> http://fgaucho.dyndns.org:8080/footprint-service/admin/config/123
>>>
>>> This returns an XML (because the JAXBElement is being automatically
>>> unmarshalled to XML ).. how do I read it as JSON string ??
>>>
>>> * the fragment of code I am using as example:
>>>
>>> @GET
>>> @Produces( { MediaType.APPLICATION_XML,
>>> MediaType.APPLICATION_JSON
>>> })
>>> public JAXBElement<FootprintConfig>
>>> get(@PathParam("config_id")
>>> String id) {
>>> JAXBElement<FootprintConfig> jbe =
>>> factory.createConfiguration(factory
>>> .createFootprintConfig());
>>> return jbe;
>>> }
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>>> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>>>
>>
>>