users@jaxb.java.net

marshal without envelope tag

From: Tomasz Toczyski <guf_at_kajak.org.pl>
Date: Tue, 23 Dec 2008 15:57:27 +0100 (CET)

Suppose I have an object myObject of a class generated by JAXB. I would
like to marshall myObject to XML without envelope tag. In JAXB v1 I used
to write:

marshaller.marshal( myObject, outputStream );

But when I try the same with JAXB v2 I get an MarshalException:
[com.sun.istack.SAXException2: unable to marshal type "MyType" as an
element because it is missing an @XmlRootElement annotation]

I know that I can avoid this exception by i.e. wrapping myObject with
JAXBElement with some QName object but it marshal to XML with envelope tag
correnponding to the QName object. But I don't want to have the envelope
tag.

Is there any elegant solution to my problem?

Of course I can marshal to string with an envelope tag and trim off the
envelope tag. But it is not an elegant solution.

Regards,
-tt.