Skip to content

HyperJAXB3 Miscellaneous customizations

Laurent Schoelens edited this page May 17, 2024 · 1 revision

Miscellaneous customizations

Customizing JAXB context path

"Any"-type properties need a JAXB context for marshalling/unmarshalling operations. By default the context path of this JAXB context is derived from the compiled schemas. In some cases it may not be suitable and you may want to customize the context path. In order to do it, you may use the hj:jaxb-context customization element:

<xsd:element name="any" type="xsd:anyType">
    <xsd:annotation>
        <xsd:appinfo>
            <hj:generated-property propertyName="Anything">
                <hj:jaxb-context contextPath="org.jvnet.hyperjaxb3.ejb.tests.po"/>
            </hj:generated-property>
        </xsd:appinfo>
    </xsd:annotation>
</xsd:element>

Produces:

public static final String AnythingContextPath = "org.jvnet.hyperjaxb3.ejb.tests.po";
 
public String getAnything() {
    if (JAXBContextUtils.isMarshallable(AnythingContextPath , this.getAny())) {
        return JAXBContextUtils.marshal(AnythingContextPath , this.getAny());
    } else {
        return null;
    }
}
 
public void setAnything(String target) {
    if (target!= null) {
        setAny(JAXBContextUtils.unmarshal(AnythingContextPath , target));
    }
}

You can make the context path field non-final:

<hj:jaxb-context ...>
    <hj:field final="false"/>
</hj:jaxb-context>
Clone this wiki locally