users@jersey.java.net

Re: [Jersey] Java generics with Jersey

From: Damiano ALBANI <damiano.albani_at_univ-nantes.fr>
Date: Thu, 07 Oct 2010 18:02:47 +0200

Hello,

On Thu, 2010-10-07 at 16:26 +0200, Paul Sandoz wrote:


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


Hum, OK, I'm no JAXB expert as you are :-)
And I suppose there's no way to "hint" the JAXB context with some
additional request-specific information?
Anyway, adding a "type" property is not so troublesome after all.


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


Well, I might have exaggerated in saying that, but at least, I saw that
the JAXB annotations like @XmlElement(name = "att_name") were not
applied with Jackson. I get the JSON properties in the original Java
camel-case.


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


I don't know if that's clean Java code but I found a solution:

    public MyWebAppTest() throws Exception {
        super(
            new WebAppDescriptor.Builder("here.my.packages")
                                .contextPath("spin")
                                .clientConfig(
                                    new DefaultClientConfig() {
                                        {

this.getClasses().add(JAXBContextResolver.class);
                                        }
                                    }
                                )
                                .build()
        );
    }

And then my JAXB context resolver is used in all the tests.

-- 
Damiano ALBANI