How can I add xml attributes to jaxb annotated class XmlElementWrapper?

Viewed 62440

I have a class with a XmlElementWrapper annotation like:

...

  @XmlElementWrapper(name="myList")
    @XmlElements({
    @XmlElement(name="myElement") }
    )
    private List<SomeType> someList = new LinkedList();

... This code produces XML like

<myList>
  <myElement> </myElement>
  <myElement> </myElement>
  <myElement> </myElement>
</myList>

so far so good.

But now I need to add attributes to the list tag to get XML like

<myList number="2">
  <myElement> </myElement>
  <myElement> </myElement>
  <myElement> </myElement>
</myList>

Is there a 'smart way to achieve this without creating a new class that contains represents the list?

3 Answers
Related