• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JAXB Marshalling Object-Array Nesting Issue

 
Perry Terrance
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 656
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic