Castor
Skip to end of metadata
Go to start of metadata

Castor

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.

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.

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

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>.

Options

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

Dependencies

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).

Labels
  • No labels