Available as of Camel 2.1

Castor is a Data Format which uses the Castor XML library to unmarshal an XML payload into Java objects or to marshal Java objects into an XML payload.

As usually you can use either Java DSL or Spring XML to work with Castor Data Format.

Using the Java DSL


For example the following uses a named DataFormat of Castor which uses default Castor data binding features.

CastorDataFormat castor = new CastorDataFormat ();


If you prefer to use a named reference to a data format which can then be defined in your Registry such as via your Spring XML file. e.g.


If you want to override default mapping schema by providing a mapping file you can set it as follows.

CastorDataFormat castor = new CastorDataFormat ();

Also if you want to have more control on Castor Marshaller and Unmarshaller you can access them as below.


Using Spring XML

The following example shows how to use Castor to unmarshal using Spring configuring the castor data type

<camelContext id="camel" xmlns="">
    <from uri="direct:start"/>
      <castor validation="true" />
    <to uri="mock:result"/>

This example shows how to configure the data type just once and reuse it on multiple routes. You have to set the <castor> element directly in <camelContext>.

<camelContext id="camel" xmlns="">
    <castor id="myCastor"/>

    <from uri="direct:start"/>
    <marshal ref="myCastor"/>
    <to uri="direct:marshalled"/>
    <from uri="direct:marshalled"/>
    <unmarshal ref="myCastor"/>
    <to uri="mock:result"/>



Castor supports the following options

Option Type Default Description
encoding String UTF-8 Encoding to use when marshalling an Object to XML
validation Boolean false Whether validation is turned on or off.
mappingFile String null Path to a Castor mapping file to load from the classpath.
packages String[] null Add additional packages to Castor XmlContext
classNames String[] null Add additional class names to Castor XmlContext


To use Castor in your camel routes you need to add the a dependency on camel-castor which implements this data format.

If you use maven you could just add the following to your pom.xml, substituting the version number for the latest & greatest release (see the download page for the latest versions).

© 2004-2011 The Apache Software Foundation.
Apache Camel, Camel, Apache, the Apache feather logo, and the Apache Camel project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
Graphic Design By Hiram