users@jersey.java.net

Re: [Jersey] JSON providers

From: Tom <808131_at_gmail.com>
Date: Mon, 21 Dec 2009 16:11:39 +0000

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?

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
>>