users@jersey.java.net

Re: [Jersey] Jersey register only one class to JAXB marshaller at a time

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 30 Jun 2009 08:09:46 +0200

Hi,

The default behavior, in absence of configuration by the application,
is to utilize a JAXB context created from the JAXB root element or
type class. JAXB will work out any dependencies it can (as you found
out it cannot work all dependencies).

You can declare your own JAXB context using an implementation of
ContextResolver<JAXBContext>. See the following:

https://jersey.dev.java.net/documentation/1.1.0-ea/user-
guide.html#d4e457

Although it defines it for JSON confguration using JSONJAXBContext the
same applies to just using JAXBContext instead.

Paul.




On Jun 30, 2009, at 7:49 AM, testn wrote:

>
> It seems like JAXB Provider in Jersey only registers one class of the
> returned type only for marshalling/unmarshalling data. Therefore, it
> cannot
> handle cases like this properly
>
> 1. public A getA()
>
> where A is the base class and has B and C inherited from it. If getA()
> returns instance of B or C, only contents in A are marshalled.
>
> 2. public A[] getAllA()
>
> where A is the base class and has B and C inherited from it. If getA()
> returns instance of B or C, only contents in A are marshalled.
>
> 3 public A getA()
> where A refers to some other classes like
>
> @XmlRootElement("A")
> public class A {
> public B b;
> }
>
> @XmlRootElement("B")
> {
> public int propB;
> }
>
> Instead of getting marshalled to
>
>
>
> <propB>1</propB>
>
>
>
>
> but it seems to be marshalled as
>
>
>
> <propB>1</propB>
>
>
>
> --
> View this message in context: http://n2.nabble.com/Jersey-register-only-one-class-to-JAXB-marshaller-at-a-time-tp3179530p3179530.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>