• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

Unmarshalling of nested child elements using jaxb

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I ask regarding the java jaxb, if we have nested child elements in the xml document, how do we unmarshal it using java objects?

I am able to unmarshal all the single elements.
However for the nested child, I have difficulty unmarshalling the phone-type and phone-number in the PhoneNumber.class.

Attached are my files and the main method below to call the unmarshalling of xml.

<person>
<id>123</id>
<first-name>john</first-name>
<last-name>tan</last-name>
<phone-numbers total="1">
<phone-number>
<phone-type>mobile</phone-type>
<phone-number>12345678</phone-number>
</phone-number>
</phone-numbers>
<email-address>asd@gmail.com</email-address>
</person>







Thank you!
 
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Junliang,
Questions regarding XML are better answered in our XML forum. I am moving this to the XML forum.
 
Ranch Hand
Posts: 729
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[0] You've decided to let go the attribute "total", that's fine as you like it to be.

[1] This is how you can rewrite your UserLinkedIn class taking into account of the wrapping element phone-numbers. The simplest way is to make it an inner class of UserLinkedIn so that the general layout will be preserve with minimum rewrite. This is how.

[2] Now the unmarshalling to verify everything is in place can look like this.
 
No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!