Is it possible to marshal java classes (annotated with JAXB annotations) by StAX without using JAXB itself?

有帮助吗?

解决方案

No, to marshall with JAXB annotations, you need JAXB - that's what it does. Yes, you can use StAX as the output writer when you serialize a JAXB object tree using a Marshaller.

They are two separate things. StAX is not faster than JAXB, it does something different - it is needed to create textual XML after JAXB has generated the correct XML events to tell StAX what the XML should look like.

Use the following method on javax.xml.bind.Marshaller to send your JAXB objects to StAX:

/**
 * Marshal the content tree rooted at <tt>jaxbElement</tt> into a
 * {@link javax.xml.stream.XMLStreamWriter}.
 *
 * @param jaxbElement
 *      The content tree to be marshalled.
 * @param writer
 *      XML will be sent to this writer.
 *
 * [...]
 * @since JAXB 2.0
 */
public void marshal( Object jaxbElement, javax.xml.stream.XMLStreamWriter writer )
    throws JAXBException;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top