JAXB Annotations

前端 未结 1 1750
无人共我
无人共我 2020-12-09 10:46

I need a little help with JAXB Annotations and I couldn\'t find good doc\'s helping me figure this out.

I have a class that I want to marshal into XML. My Class look

相关标签:
1条回答
  • 2020-12-09 11:26

    Try this:

    @XmlRootElement(name="car")
    ...
    public class Car {
       ...
    
       @XmlElementWrapper(name="recalls")  // this name=... can be omitted, as it
                                           // is the same as the field name
       @XmlElement(name="recall")
       private ArrayList<Recall> recalls;
    }
    

    From the documentation:

    XmlElementWrapper: Generates a wrapper element around XML representation. This is primarily intended to be used to produce a wrapper XML element around collections.

    0 讨论(0)
提交回复
热议问题