aspose file tools*
The moose likes XML and Related Technologies and the fly likes JAXB Marshalling Object-Array Nesting Issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "JAXB Marshalling Object-Array Nesting Issue" Watch "JAXB Marshalling Object-Array Nesting Issue" New topic
Author

JAXB Marshalling Object-Array Nesting Issue

Perry Terrance
Ranch Hand

Joined: Oct 02, 2009
Posts: 60
This has to be very simple, but I can't figure out whats going on.

I have a simple JAXB POJO myPOJO - which only has one field of an array of Objects - myObjects which has two instances of Object innerObject in it. The innerObject has a single String Field of "test".

So it goes like this:

myPOJO -> [] myObjects array-> array of [innerObject("test"), innerObject("test")]



When I marshal this Java to XML - I expect to get the following structure:




instead I get this:




Why is my innerObject array nested like this and where is innerObject's own XML element-name? Why are there 2 XML-elements of myObjects when it is a single Object array?

I have only one XML JAXB annotation of @XmlRootElement at the top-level myPOJO class...




g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 547
    
    3

I have only one XML JAXB annotation of @XmlRootElement at the top-level myPOJO.java class...

In that case, you're using default XmlAccessorType. The minimum you can do is to add these two annotations to your public getter (the property) on List<MyObject> like this.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JAXB Marshalling Object-Array Nesting Issue