users@jersey.java.net

Re: [Jersey] Re: consuming xml

From: Pavel Bucek <Pavel.Bucek_at_Sun.COM>
Date: Mon, 08 Mar 2010 14:35:03 +0100

I was probably too brief and additionally didn't answered your question
from JAX-RS perspective.

there are two scenarios:


1) when passing JAXB object as a parameter to resource class method

When you specify plain JAXB class as a parameter, XML root element will
be discarded. JAXBElement can be used to access xml root element of
incoming message.

2) returning JAXB object from resource method

If you have class with @XmlRootElement annotation, xml root element will
be derived from that. If you don't, Jersey doesn't know how XML root
element should be constructed so you have to encapsulate your class in
JAXBElement instance, which will provide information needed to generate
xml root element (to be more concrete - you have to specify
javax.xml.namespace.QName of XML root element when creating JAXBElement
instance, see
http://java.sun.com/javase/6/docs/api/javax/xml/bind/JAXBElement.html).

Does it make more sense?

Pavel



Pavel Bucek wrote:
> JAXBElement is used for classes which don't have @XmlRootElement
> annotation.
>
> There are various documents where you can read more about that, for
> example:
>
> http://weblogs.java.net/blog/kohsuke/archive/2006/03/why_does_jaxb_p.html
> https://jaxb.dev.java.net/tutorial/section_4_1-Building-and-Marshalling-an-XML-Document.html#Building%20and%20Marshalling%20an%20XML%20Document
>
> https://jaxb.dev.java.net/tutorial/section_3_1-Unmarshalling-and-Using-the-Data.html#Unmarshalling
>
>
> Regards,
>
> Pavel
>
> emile wrote:
>> I had gone through some of the examples and they mention JAXBElement
>> as part
>> of the parameter. Please help me understand why thats included.
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>