Annotation Type XmlAnyElement


  • @Retention(RUNTIME)
    @Target({FIELD,METHOD})
    public @interface XmlAnyElement
    Maps a JavaBean property to XML infoset representation and/or JAXBElement.

    This annotation serves as a "catch-all" property while unmarshalling xml content into an instance of a Jakarta XML Binding annotated class. It typically annotates a multivalued JavaBean property, but it can occur on single value JavaBean property. During unmarshalling, each xml element that does not match a static @XmlElement or @XmlElementRef annotation for the other JavaBean properties on the class, is added to this "catch-all" property.

    Usages:

    {@snippet :
    Since:
    1.6, JAXB 2.0
    Author:
    Kohsuke Kawaguchi
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      boolean lax
      Controls the unmarshaller behavior when it sees elements known to the current JAXBContext.
      java.lang.Class<? extends DomHandler<?,​?>> value
      Specifies the DomHandler which is responsible for actually converting XML from/to a DOM-like data structure.
    • Element Detail

      • lax

        boolean lax
        Controls the unmarshaller behavior when it sees elements known to the current JAXBContext.
        When false
        If false, all the elements that match the property will be unmarshalled to DOM, and the property will only contain DOM elements.
        When true
        If true, when an element matches a property marked with XmlAnyElement is known to JAXBContext (for example, there's a class with XmlRootElement that has the same tag name, or there's XmlElementDecl that has the same tag name), the unmarshaller will eagerly unmarshal this element to the Jakarta XML Binding object, instead of unmarshalling it to DOM. Additionally, if the element is unknown but it has a known xsi:type, the unmarshaller eagerly unmarshalls the element to a JAXBElement, with the unknown element name and the JAXBElement value is set to an instance of the Jakarta XML Binding mapping of the known xsi:type.

        As a result, after the unmarshalling, the property can become heterogeneous; it can have both DOM nodes and some Jakarta XML Binding objects at the same time.

        This can be used to emulate the "lax" wildcard semantics of the W3C XML Schema.

        Default:
        false
      • value

        java.lang.Class<? extends DomHandler<?,​?>> value
        Specifies the DomHandler which is responsible for actually converting XML from/to a DOM-like data structure.
        Default:
        jakarta.xml.bind.annotation.W3CDomHandler.class