问题
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