tags:

views:

38

answers:

1

Hello,

If I have an object that contains a few fields that are Lists of other objects, and I want to generate the XML to represent that object, I get something like this

<top level object>
  <object1 />
  <object1 />
  <object1 /> 
  <object2 />
  <object2 />
  <object3 />
</top level object>

and I want to generate something like this:

<top level object>
  <object1 list>
    <object1 />
    <object1 />
    <object1 /> 
  </object1 list>
  <object2 list>
    <object2 />
    <object2 />
  </object2 list>
  <object3 />
</top level object>

Is this possible by modifying my annotations? Right now I have my top level class object marked with

 @XmlRootElement()

and each of the Object1, Object2...etc getters (that returns a List < Object#> )has the

@XmlElement()

annotation.

Hopefully there is a way to change my output by modifying the annotations, because it seems silly to me to make a "Object1List" object to simply hold a getter for the other lists to make this work the way I am picturing in my head

Thanks!

+3  A: 

Take a look at XmlElementWrapper on java.net or in the Java 6 API. I think that it is exactly what you are after.

D.Shawley
This was exactly it. Thanks! I tried finding a list of hte annotations and I guess I missed that one, or missed how to use it at least
Derek
@Derek. That happens all of the time. I think that most of the value of StackOverflow is it gives you access to what little details stuck in other peoples heads ;)
D.Shawley