It's not a secret anymore!*
The moose likes Performance and the fly likes UnMarshalling and Marshalling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "UnMarshalling and Marshalling" Watch "UnMarshalling and Marshalling" New topic

UnMarshalling and Marshalling

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1371
I am evaluating JAXB and Castor for UnMarshalling(XML-> Java Objects ) and Marshalling(Java Objects -> XML). Which gives better performance ?
Anurag Blore
Ranch Hand

Joined: Jan 15, 2003
Posts: 74
I am not sure about CASTOR but JAXB has performance issue when you have lot of data. I have faced it, the data gets returned in 2 second but while marshalling takes lot of time and gives us out of memory error. This could be due to the xml element names(more than 15 characters in some case) in my xsd.

Taariq San
Ranch Hand

Joined: Nov 20, 2007
Posts: 192
Also look at JIBX, if performance is a serious consideration.
kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1371
Hi Anurag, How xml element names more than 15 characters in xsd gives outOfMemoryError ?

Anurag Blore
Ranch Hand

Joined: Jan 15, 2003
Posts: 74

May be I was not clear in my post.

In my case we have a search and if user searched based on 2 characters then the reult returned from the database is huge and data is returned fast from the database but when we do marshalling in java It gives us heap error. Just to mention my xml result is quite complex(In the sense it has relations,attributes etc returned) So If I am returning detail of one result the xml will be big and multiple result will have more data to convert our java object to xml(marshalling). It my guess the xml contains lot of Strings attribute name and this could be the cause.

If you think I am missing something please providie your thoughts.
Hiren Dutta

Joined: Dec 30, 2005
Posts: 10
My Vote will go for JAXB. With a little trick we can save lot of JAXB marshalling and unmarshalling time. JAXB spends most of the time to create JAXB context. We just have to make JAXBContext static final. If you are using multiple JAXBContext, create 1st time and keep in static Hashmap.
Bhaskar Rao

Joined: Apr 25, 2005
Posts: 23

I haven't evaluated JAXB for performance. But one advantage I found with CASTOR was that it does not mandate the use of XSDs.

Databases can return entire ResultSets as XML which you can then transform to whatever format you want using XSLT. But again, I am not sure if the transformation itself can throw OutOfMemoryError in your case
Carey Evans
Ranch Hand

Joined: May 27, 2008
Posts: 225

JAXB doesn't need a schema; we're doing unmarshalling of a 6 MB file using JAXB, just by defining the appropriate classes with JAXB annotations. We only create the JAXBContext once.
Jegan Thangavelu

Joined: Nov 09, 2006
Posts: 1

I did some research on this and found that ,apache XMLBeans seems to be faster in marshalling and unmarshalling and also CPU utilization is less.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15960

Maybe I'm being unfair to Castor, but at one time it was the only game in town, and it did a good job. These days, you don't hear that much about it, so I'm thinking that it no longer is the optimal tool for most tasks. In fact, I think that the JOnAS project switched from Castor to Zeus, and then abandoned Zeus for something more along the lines of a mainstream standard.

Of course, there also seemed to be a certain amount of ill-will among some because Castor claimed the acronym JDO, despite the conflict with the real JDO, so some of that could be politics.

On the inbound side, the Apache Digester remains popular. I've also used STaX where I wanted directed streaming input.

Finally, there are some JPA implementations that can persist to/from XML, if that's useful.

Customer surveys are for companies who didn't pay proper attention to begin with.
Praveen Sharma
Ranch Hand

Joined: Jul 31, 2008
Posts: 129
You can have a look at this :

SCJP 80% SCWCD 89%
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: UnMarshalling and Marshalling
Similar Threads
What are the ways to convert java type to xsd type?
Marshalling and UnMarshalling
XML Marshalling and UnMarshalling
compare two XML files using DOM parser