JAXB: list and element with the same name

[亡魂溺海] 提交于 2021-01-28 05:09:36

问题


I have an XML like this.

<Node>
<a> </a>
    <metadata>
        <metadata>
            <id></id>
        </metadata>
        <metadata>
            <id></id>
        </metadata>
        <metadata>
            <id></id>
        </metadata>
    </metadata>
</Node>

where the name of the list is the same of its element. How Can I map this in JAXB?


回答1:


try this

@XmlRootElement
public class Node {
    @XmlElementWrapper(name = "metadata")
    List<Metadata> metadata;

    static class Metadata {
        @XmlElement
        String id;
    }


来源:https://stackoverflow.com/questions/18959176/jaxb-list-and-element-with-the-same-name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!