Java @XmlElementWrapper 用于解包集合

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16202583/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 05:45:54  来源:igfitidea点击:

@XmlElementWrapper for unwrapped collections

javaxmljaxb

提问by timmy

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

文档说明@XmlElementWrapper注释可用于“未包装”或“包装”集合。

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

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

How do you configure it to produce an unwrapped collection?

您如何配置它以生成未包装的集合?

采纳答案by bdoughan

If you include @XmlElementWrapperit will add a grouping element:

如果包含@XmlElementWrapper它将添加一个分组元素:

@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

想要查询更多的信息