Contact Us 1-800-596-4880

JAXB Transformers

The JAXB transformers allow objects to be serialized to XML and back again using the JAXB binding framework. To configure a transformer that will convert XML to a Person object use

<mulexml:jaxb-xml-to-object-transformer name="XmlToPerson" jaxbContext-ref="myJaxb" returnClass="org.mule.jaxb.model.Person"/>

You can then reference this transformer from an endpoint:

<jms:inbound-endpoint queue="another.queue" transformer-refs="XmlToPerson" />

The returnClass is a common transformer attribute and defines that this transformer will create a Person object.

Note that we have a reference to a JAXBContext via the jaxbContext-ref attribute, you can create this context object in your configuration file.

<mulexml:jaxb-context name="myJaxb" packageNames="org.mule.jaxb.model"/>
You can always use Spring to create objects as well. To create the JAXBContext using spring you could add the following to your Mule XML configuration too.

The opposite transformer would allow you to convert from a Person object to XML -

<mulexml:jaxb-object-to-xml-transformer name="PersonToXml" jaxbContext-ref="myJaxb"/>

JAXB Bindings

Mule offers automatic JAXB Bindings so you don’t even need use these transformers for most scenarios.

View on GitHub