users@jersey.java.net

Re: [Jersey] Java generics with Jersey

From: Damiano ALBANI <damiano.albani_at_univ-nantes.fr>
Date: Thu, 07 Oct 2010 12:35:01 +0200

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


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

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

-- 
Damiano ALBANI