Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@XmlElementWrapper for unwrapped collections

Tags:

java

xml

jaxb

The docs state the the @XmlElementWrapper annotation can be used for 'unwrapped' or 'wrapped' collections.

http://docs.oracle.com/javaee/5/api/javax/xml/bind/annotation/XmlElementWrapper.html

How do you configure it to produce an unwrapped collection?

like image 773
timmy Avatar asked Apr 24 '13 21:04

timmy


1 Answers

If you include @XmlElementWrapper it will add a grouping element:

@XmlElementWrapper
@XmlElement(name="foo")
public List<Foo> getFoos() {
    return foos;
}
<root>
    <foos>
        <foo/>
        <foo/>
    </foos>
</foo>

and if you omit it, then it won't.

@XmlElement(name="foo")
public List<Foo> getFoos() {
    return foos;
}
<root>
    <foo/>
    <foo/>
</foo>

For More Information

  • http://blog.bdoughan.com/2012/12/jaxb-representing-null-and-empty.html
like image 61
bdoughan Avatar answered Sep 18 '22 17:09

bdoughan