2

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!

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

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. 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 ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.