14.8 JiBX

The JiBX framework offers a solution similar to that which JDO provides for ORM: a binding definition defines the rules for how your Java objects are converted to or from XML. After preparing the binding and compiling the classes, a JiBX binding compiler enhances the class files, and adds code to handle converting instances of the classes from or to XML.

For more information on JiBX, refer to the JiBX web site. The Spring integration classes reside in the org.springframework.oxm.jibx package.

14.8.1 JibxMarshaller

The JibxMarshaller class implements both the Marshaller and Unmarshaller interface. To operate, it requires the name of the class to marshall in, which you can set using the targetClass property. Optionally, you can set the binding name using the bindingName property. In the next sample, we bind the Flights class:

<beans>

    <bean id="jibxFlightsMarshaller" class="org.springframework.oxm.jibx.JibxMarshaller">
        <property name="targetClass">org.springframework.oxm.jibx.Flights</property>
    </bean>

    ...

A JibxMarshaller is configured for a single class. If you want to marshal multiple classes, you have to configure multiple JibxMarshallers with different targetClass property values.

14.8.1.1 XML Schema-based Configuration

The jibx-marshaller tag configures a org.springframework.oxm.jibx.JibxMarshaller. Here is an example:

<oxm:jibx-marshaller id="marshaller" target-class="org.springframework.ws.samples.airline.schema.Flight"/>

Available attributes are:

AttributeDescriptionRequired
idthe id of the marshallerno
target-classthe target class for this marshalleryes
bindingNamethe binding name used by this marshallerno