“xsi:type” and “xmlns:xsi” in generated xml by JAXB

前端 未结 1 389
囚心锁ツ
囚心锁ツ 2021-01-11 19:53

I use JAXB to create folder and files hierarchy

My model:

@XmlRootElement
public class Root {

    @XmlAttribute
    private String path;

    @XmlE         


        
相关标签:
1条回答
  • 2021-01-11 20:47

    In your Dir class you are not specifying the type of your collection this is why JAXB is adding the xsi:type attributes.

    You have:

    @XmlElement(name = "dir")
    private ArrayList dirs;
    

    If your ArrayList is going to contain instances of Dir then you can do:

    @XmlElement(name = "dir")
    private ArrayList<Dir> dirs = null;
    

    If for some reason you don't want to specify the type on the collection then you can do it in the @XmlElement annotation:

    @XmlElement(name = "dir", type=Dir.class)
    private ArrayList dirs = null;
    
    0 讨论(0)
提交回复
热议问题