Example usage for javax.xml.bind Marshaller setAdapter

List of usage examples for javax.xml.bind Marshaller setAdapter

Introduction

In this page you can find the example usage for javax.xml.bind Marshaller setAdapter.

Prototype

public void setAdapter(XmlAdapter adapter);

Source Link

Document

Associates a configured instance of XmlAdapter with this marshaller.

Usage

From source file:org.springframework.oxm.jaxb.Jaxb2Marshaller.java

/**
 * Template method that can be overridden by concrete JAXB marshallers for custom initialization behavior.
 * Gets called after creation of JAXB {@code Marshaller}, and after the respective properties have been set.
 * <p>The default implementation sets the {@link #setMarshallerProperties(Map) defined properties}, the {@link
 * #setValidationEventHandler(ValidationEventHandler) validation event handler}, the {@link #setSchemas(Resource[])
 * schemas}, {@link #setMarshallerListener(javax.xml.bind.Marshaller.Listener) listener}, and
 * {@link #setAdapters(XmlAdapter[]) adapters}.
 *///from   w w  w. j ava2  s  .  c o m
protected void initJaxbMarshaller(Marshaller marshaller) throws JAXBException {
    if (this.marshallerProperties != null) {
        for (String name : this.marshallerProperties.keySet()) {
            marshaller.setProperty(name, this.marshallerProperties.get(name));
        }
    }
    if (this.marshallerListener != null) {
        marshaller.setListener(this.marshallerListener);
    }
    if (this.validationEventHandler != null) {
        marshaller.setEventHandler(this.validationEventHandler);
    }
    if (this.adapters != null) {
        for (XmlAdapter<?, ?> adapter : this.adapters) {
            marshaller.setAdapter(adapter);
        }
    }
    if (this.schema != null) {
        marshaller.setSchema(this.schema);
    }
}