Search code examples
javaxmljaxbpojo

Java JAXB how to create POJO classes


With JAXB, how can I create the POJO classes with such a xml structure :

 <procedure>
    <procedure>
       <param>value1</param>
       <param>value2</param>
    </procedure>
    <procedure>
       <param>value3</param>
       <param>value4</param>
    </procedure>
 </procedure>

As you can see the external procedure tag is the same than the internal procedure tag.


Solution

  • What's so special about the outer/inner procedure element names?

    Probably something like:

    @XmlRootElement(name="procedure")
    public class 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.