users@jersey.java.net

Re: [Jersey] Java generics with Jersey

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Thu, 7 Oct 2010 16:26:04 +0200

On Oct 7, 2010, at 12:35 PM, Damiano ALBANI wrote:
> Hello,
>
> On Thu, 2010-10-07 at 11:29 +0200, Paul Sandoz wrote:
>
>> No, because JAXB needs the type information in the document to
>> correctly determine the XML type to use to unmarshal the data.
>
> But why shall this type information required in this case whereas it
> is not when I don't use generics?
> By looking at the signature of the @PUT method, Jersey should be
> able to determine the expected type, shouldn't it?
> Or is it because of type erasure thing in Java?
>

When the JAXB context is instantiated all it knows about is
ExtJsWrapper.class and Campagne.class, it knows nothing about the Java
type ExtJsWrapper<Campagne> even though Jersey does.

So when JAXB is asked to unmarshal ExtJsWrapper.class it sees, using
reflection, the field "rows" as the class Object.


>> When you marshall is the type property included?
>
> Yes, it is.
>
>
>> In XML this property is an attribute and attributes occur before
>> the element content. Since JSON has no concept of attributes the
>> convention here is any properties associated with attributes in the
>> XML infoset for JAXB need to occur first.
>
> Ok, I see. Still, that's a bit strange in a JSON point of view when
> there's no order in properties AFAIK :-)
>

Agreed, that is the issue with mapping XML infoset <-> JSON.


>
>> You may want to consider using Jackson instead to avoid these types
>> of mapping artifacts. Jakub/Tatu can provide more details.
>
> Oh I see -- I actually thought that Jersey used Jackson by default...
> But I've done some quick tests and it seems that using Jackson
> departs from the whole JAX-RS idea.
>

Why?


>> Off list we communicated that you are using a ContextResolver on
>> the client side. Can you share the code on how you are registering
>> it on the client side? is it like the following:
>
> Yeah, that was the missing bit -- I had forgotten that Jersey Client
> API need its own configuration.
> I can now successfully send/receive wrapper objects using the client
> API.
> Thanks a million Paul !
>
> Final remaining bit: how to specify this ContextResolver when using
> the JerseyTest class for my tests, as the Client is automatically
> instantiated...
> Overriding "public Client client()" with my own method didn't seem
> to do the trick :-(
>

Pavel?

Paul.