Java JAXB xml pojo classes

和自甴很熟 提交于 2020-01-06 19:49:39

问题


How can I create the POJO classes with JAXB with such a xml structure :

<principale>
   <procedure>
      <procedure>
         <param1>value1</param1>
         <param2>value2</param2>
      </procedure>
      <procedure>
         <param1>value3</param1>
         <param2>value4</param2>
      </procedure>
   </procedure>
</principale>

As you can see the first procedure tag is not the root one and is the same than the second procedure tag.


回答1:


If the outer procedure element is not repeatable, try it with @XmlElementWrapper:

@XmlRootElement(name="principale")
public class Principale {
    @XmlElementWrapper(name="procedure")
    @XmlElement(name="procedure")
    public List<Params> procedures = new LinkedList<Params>();
}
public class Params {
   @XmlElement(name="param")
   public List<String> params = new LinkedList<String>();
}

(Untested.)



来源:https://stackoverflow.com/questions/26823002/java-jaxb-xml-pojo-classes

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