• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unmarshalling of nested child elements using jaxb

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic