This week's giveaway is in the Threads forum.
We're giving away four copies of Java Concurrency Live Lessons and have Doug Schmidt on-line!
See this thread for details.
Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What type of marshalling does JAXB use?  RSS feed

 
Luke Murphy
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good answer thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!