It's not a secret anymore!
The moose likes XML and Related Technologies and the fly likes Help With JaxB Unmashalling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Help With JaxB Unmashalling" Watch "Help With JaxB Unmashalling" New topic

Help With JaxB Unmashalling

Darren Carter
Ranch Hand

Joined: Jul 08, 2010
Posts: 30
Hi Everyone,

I have a XML docment in which I need to unmarshall into a java object using jaxb. I am a little unclear of how I should map the xml annotations in my pojo and was hoping someone could advise?

my XML document is


Can any one tell me how I would map this using annotations? so for example card_name should be mapped to cardName.


Karthik Shiraly

Joined: Apr 04, 2009
Posts: 758

From the <struct> and <member> tags, this looks to me like the response of an XML-RPC web service.

In my opinion, this kind of response is not very convenient to process using JAXB, though I think it is possible using custom unmarshalling adaptor. If getting a Card object by other simpler methods is ok, then read on.

You can use Apache XMLRPC library (Download link), since it can interpret XMLRPC responses correctly.
It'll convert the <struct> element to a Map and each <member> to a Map entry.

Next, iterate through this Map's entries and convert the underscored keys to java camelcase (like "card_name" to "cardName") using Guava library's CaseFormat class

Finally, convert this Map to Card object using Apache BeanUtils. It'll also need Apache Collections 3.2.x framework to work.
Tony Evans
Ranch Hand

Joined: Jun 29, 2002
Posts: 595
Would you not be better of generating the object from the XML schema that will sort out all your annotations for you.
I agree. Here's the link:
subject: Help With JaxB Unmashalling
It's not a secret anymore!