开发者

jaxb: How can I bind nested element

开发者 https://www.devze.com 2023-01-03 22:05 出处:网络
There is my xml: <parent> <children> <child>1</child> <child>开发者_运维技巧2</child>

There is my xml:

<parent>
   <children>
      <child>1</child>
      <child>开发者_运维技巧2</child>
   </children>
</parent>

I want to have the following Parent class:

@XmlRootElement
Parent{
   @XmlElement(name="children/child") 
   List<Child> children;
}

I don't want to have class for element 'children'. How should I map field children ?


Use @XmlElementWrapper:

@XmlRootElement
public class Parent {
   @XmlElementWrapper(name="children")
   @XmlElement(name="child") 
   List<Child> children;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消