JAXB - Ignore element

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

    JAXB will ignore any unmapped properties.

    Implementation wise (atleast in EcliseLink JAXB (MOXy), which I lead). When we are processing the contents via a SAX parser (i.e. the input was a SAXSource) then we swap out our ContentHandler that is responsible for building objects to one that does no processing for that section (org.eclipse.persistence.oxm.unmapped.UnmappedContentHandler). When a we are using processing the contents via a StAX parser we just advance to the next mapped event.

    If you do have a property that corresponds to that node you can annotate it with @XmlTransient to make it an unmapped property.

提交回复
热议问题