This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Web Services and the fly likes What type of marshalling does JAXB use? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Web Services
Reply Bookmark "What type of marshalling does JAXB use? " Watch "What type of marshalling does JAXB use? " New topic
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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: What type of marshalling does JAXB use?
 
Similar Threads
Anybody using StAX?
Too Many XML Related Technologies: Please Advise
Which parser does JAXB use?
JAXB, DOM, SAX
Which XML technique to use?