Guide to Transformer (Message Transformation)

Transformer performs declarative transformation of the message according to the declared Input Type and/or Output Type on a route definition. The default camel message implements DataTypeAware, which holds the message type represented by DataType.

It is within the route definition that we declare the Input Type and/or Output Type. If the Input Type and/or Output Type are different from the message type at runtime, the camel internal processor looks for a Transformer. The role of the Transformer is to transform the current message type to the expected message type. Once the message is transformed successfully or if the message is already in the expected type, then the message data type is updated.

Supported Transformers

Transformer

Description

Transformer

Description

Data Format Transformer

Transforms by using Data Format

Endpoint Transformer

Transforms by using Endpoint

Custom Transformer

Transforms by using custom transformer class.

Transformer Options

Name

Description

Name

Description

scheme

Type of data model such as xml or json. For example, if xml is specified, the transformer is applied for all java -> xml and xml -> java transformation.

fromType

Data type to transform from.

toType

Data type to transform to.

Transformer Examples

Java DSL:

BindyDataFormat bindy = new BindyDataFormat(); bindy.setType(BindyType.Csv); bindy.setClassType(com.example.Order.class); transformer() .fromType(com.example.Order.class) .toType("csv:CSVOrder") .withDataFormat(bindy);

XML DSL:

<dataFormatTransformer fromType="java:com.example.Order" toType="csv:CSVOrder"> <bindy id="csvdf" type="Csv" classType="com.example.Order"/> </dataFormatTransformer>

Customer Transformer

Examples to illustrate custom Transformer class:

Java DSL:

transformer() .fromType("xml") .toType("json") .withJava(com.example.MyCustomTransformer.class);

XML DSL:

Declaration of an Endpoint using XSLT component:

Java DSL:

XML DSL: