users@jersey.java.net

Re: [Jersey] JSON providers

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 29 Dec 2009 10:23:59 +0100

On Dec 21, 2009, at 5:11 PM, Tom wrote:

> Hi Jakub,
>
> On Wed, Dec 16, 2009 at 2:08 PM, Jakub Podlesak <Jakub.Podlesak_at_sun.com
> > wrote:
>>> I've seen that I have various options for generating JSON (Jersey,
>>> Jettison, Jackson, etc.) and there is mention of a
>>> JAXBContextResolver
>>> but I don't understand how these fit together, or even if they are
>>> the
>>> same thing.
>>
>> JAXBContextResolver applies only when JAXB based JSON
>> (de)serialization
>> is used. Then on the server side, the resolver is found
>> automatically,
>> when the application packages are scanned by Jersey runtime.
>> On the client side, you would need to register the resolver manualy:
>>
>> ClientConfig config = new DefaultClientConfig();
>> config.getClasses().add(YourJAXBContextResolver.class);
>> Client client = Client.create(config);
>
> In my experimental Jersey server I had tried adding jettison to the
> classpath but I don't think it was using it. Ideally, it would be nice
> to be able to run all options so that I could compare the output and
> get a better feeling. Is it possible to have three jersey servlets
> running with different configurations?
>

Yes, if you appropriately isolate the application configuration for
each servlet (in this case the JSON convention utilized, it should
also be possible to use Jackson JAX-RS support as well).

For deployment configuration see:

   https://jersey.dev.java.net/nonav/documentation/latest/user-guide.html
#d4e194

Paul.

> I will have another look around and certainly work my way through more
> of the examples (the low-level approach sounds interesting) - and then
> I'll be back ;-)
>
> Thanks for your help.
>
> Regards,
> Tom
>
>>
>>>
>>
>> The other two options are:
>>
>> i) low-level JSONObject/JSONArray based approach, where you have
>> the best control of what is being generated (see [3])
>> ii) Jacskon JAX-RS provider (see [2] for a very simple example),
>> which is capable of processing generic Java classes (no JAXB
>> annotations needed)
>>
>> HTH,
>>
>> ~Jakub
>>
>>
>> [1]http://download.java.net/maven/2/com/sun/jersey/samples/json-from-jaxb/1.1.5-ea-SNAPSHOT/json-from-jaxb-1.1.5-ea-SNAPSHOT-project.zip
>> [2]http://download.java.net/maven/2/com/sun/jersey/samples/jacksonjsonprovider/jacksonjsonprovider/1.1.5-ea-SNAPSHOT/jacksonjsonprovider-1.1.5-ea-SNAPSHOT-project.zip
>> [3]http://download.java.net/maven/2/com/sun/jersey/samples/bookmark/1.1.5-ea-SNAPSHOT/bookmark-1.1.5-ea-SNAPSHOT-project.zip
>>
>>>
>>> Thanks,
>>>
>>> Tom
>>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>