Using languages with Dozer in Camel


Dozer is a cool bit of kit that maps fields from one class to another. You can use it to perform transformations in Camel.

When it’s plugged into Camel, it can also be used to map from a Camel language expression, via custom converters. This support is in the ExpressionMapper class. This means you can use Dozer with things like Simple language, Groovy, OGNL expressions, and so on.

You might find this feature useful if you want to do more complex mapping, or if you want to map things other than simple Java fields - for example, if you want to map the result of method calls.

You just need to set org.apache.camel.component.dozer.ExpressionMapper as the source class in your mapping file, and then add your expression in the custom-converter-param attribute on a field element:


  <field custom-converter-id="_expressionMapping"

Here are some examples:

Camel language Example What it does
Simple custom-converter-param="simple:\${body.customerName}" Use the result of getCustomerName() method on the Exchange body
Groovy custom-converter-param="groovy:return request.headers.Employee" Use the content of the Employee header


Here’s a full example of a Dozer mapping file, showing how to use Groovy and Simple expressions inside the file.

In this example, I’m using the Simple language’s graph-notation support, to access fields on the body (simple:${body.globalId}) and similar support in Groovy (groovy:return request.headers.Employee.type).

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<mappings xmlns="" xmlns:xsi="" xsi:schemaLocation="">

    <!-- Using a Simple expression -->
    <!-- Populate the target field with 'globalId' from the body -->
    <field custom-converter-id="_expressionMapping" 

    <!-- Using a Groovy expression -->
    <!-- Populate the target field with a value from headers -->
    <field custom-converter-id="_expressionMapping" 
          custom-converter-param="groovy:return (request.headers.Employee?.type == 'Full-Time') ? : null">

Leave a Comment

You can use Markdown in your comment. To write code, indent lines by 4 spaces.