JAXB - Ignore element

后端 未结 4 921
春和景丽
春和景丽 2020-12-03 16:42

Is there any way to just ignore an element from Jaxb parsing? I have a large XML file, and if I could ignore one of the large, complex elements, then it would probably parse

4条回答
  •  [愿得一人]
    2020-12-03 17:36

    All what you need it's mark field as @XmlTransient (@XmlTransient annotation which should hide fields that are not required). Example below

    JavaEE:

    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlRootElement(name = "DeletedIds")
    public class DeletedIds {
    
        @XmlElement(name = "DeletedId")
        private List id;    
    
        @XmlTransient
        @XmlElement(name = "success")
        private String success;
    
        //getters&setters
    }
    
    @XmlAccessorType(XmlAccessType.FIELD)
    public class DeletedId {
    
        private int id;
    
        //getters&setters
    }
    

    Xml:

    
        
            1
        
        
            2
        
    
    

提交回复
热议问题