JAXB - Ignore element

后端 未结 4 924
春和景丽
春和景丽 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:34

    Assuming your JAXB model looks like this:

    @XmlRootElement(name="foo")
    public class Foo {
    
       @XmlElement(name="element1")
       String element1;
    
       @XmlElement(name="element2")
       String element2;
    
       @XmlElement(name="bar")
       Bar bar;
    }
    

    then simply removing the bar field from Foo will skip the element in the input document.

    Alternatively, annotated the field with @XmlTransient instead of @XmlElement, and it will also be skipped.

提交回复
热议问题