| Author |
What type of marshalling does JAXB use?
|
Luke Murphy
Ranch Hand
Joined: May 12, 2010
Posts: 299
|
|
Hi,
The marshalling for SAX, DOM and StAX are all well documented and it is easy to get a good understanding of them.
While I know JAXB has a nice clean API and cool annotations and makes marshalling very simple, I'd like to know how it marshalls under the hood.
My understanding is that it builds up a Tree in the same way DOM does but it is slightly more performant than DOM.
Is this correct?
Also, if it is building up a tree I presume it suffers from some of the drawbacks DOM does for example a large memory footprint. And it therefore wouldn't be as performant as StAX? Would this be correct?
Is there any way JAXB can be configured to be more performant? for example to use a Pull or PUSH model as SAX StAX does?
Many thanks.
|
 |
Karthik Shiraly
Ranch Hand
Joined: Apr 04, 2009
Posts: 366
|
|
Hi,
It can use whatever you want it to use - both Marshaller.marshal() and Unmarshaller.unmarshal() support SAX, DOM and StAX sources/readers and results.
In one of my apps, I used JAXB unmarshalling with StAX XMLEventReader and Unmarshaller.Listener.afterUnmarshal() to parse an incoming HTTP XML (of 10000+ users) as and when the tags were coming in, without having to wait for the entire HTTP response to arrive.
|
 |
Luke Murphy
Ranch Hand
Joined: May 12, 2010
Posts: 299
|
|
Karthik Shiraly wrote:Hi,
It can use whatever you want it to use - both Marshaller.marshal() and Unmarshaller.unmarshal() support SAX, DOM and StAX sources/readers and results.
In one of my apps, I used JAXB unmarshalling with StAX XMLEventReader and Unmarshaller.Listener.afterUnmarshal() to parse an incoming HTTP XML (of 10000+ users) as and when the tags were coming in, without having to wait for the entire HTTP response to arrive.
How do you configure it to use StAX, SAX or DOM then?
|
 |
Karthik Shiraly
Ranch Hand
Joined: Apr 04, 2009
Posts: 366
|
|
Hi,
It's described in the javadoc itself. I quote:
Just call the overloaded version of marshal/unmarshal that suits the approach you want.
|
 |
Luke Murphy
Ranch Hand
Joined: May 12, 2010
Posts: 299
|
|
|
Good answer thanks.
|
 |
 |
|
|
subject: What type of marshalling does JAXB use?
|
|
|