...
- The ability to manage Dozer mapping configuration on a per-endpoint basis vs. global configuration via the converter registry.
- A Dozer endpoint can be configured to marshal/unmarshal input and output data using Camel data formats to support a single, any-to-any transformation endpoint
- The Dozer component allows for fine-grained integration and extension of Dozer to support extended additional functionality (e.g. mapping constants to target fieldsliteral values, using expressions for mappings, etc.).
In order to use the Dozer component, Maven users will need to add the following dependency to their pom.xml
:
Code Block | ||||
---|---|---|---|---|
| ||||
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-dozer</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency> |
URI format
The Dozer component only supports producer endpoints.
Code Block |
---|
dozer:endpointId[?options] |
...
Name | Default | Description |
---|---|---|
| dozerBeanMapping.xml | The location of a Dozer configuration file. The file is loaded from the classpath by default, but you can use |
| none | The id of a dataFormat defined within the Camel Context to use for unmarshalling the mapping input from a non-Java type.
|
| none | The id of a dataFormat defined within the Camel Context to use for marshalling the mapping output to a non-Java type. |
| none | Fully-qualified class name for the source type used in the mapping. If specified, the input to the mapping is converted to the specified type before being mapped with Dozer. |
| none | Fully-qualified class name for the target type used in the mapping. This option is required. |
mappingConfiguration | none | The name of a DozerBeanMapperConfiguration bean in the Camel registry which should be used for configuring the Dozer mapping. This is an alternative to the mappingFile option that can be used for fine-grained control over how Dozer is configured. |
Using Data Formats with Dozer
Dozer does not support non-Java sources and targets for mappings, so it cannot, for example, map an XML document to a Java object on its own. Luckily, Camel has extensive support for marshalling between Java and a wide variety of formats using data formats. The Dozer component takes advantage of this support by allowing you to specify that input and output data should be passed through a data format prior to processing via Dozer. You can always do this on your own outside the call to Dozer, but supporting it directly in the Dozer component allows you to use a single endpoints to configure any-to-any transformation within Camel.
As an example, let's say you wanted to map between an XML data structure and a JSON data structure using the Dozer component. If you had the following data formats defined in a Camel Context:
Code Block | ||
---|---|---|
| ||
<dataFormats>
<json library="Jackson" id="myjson"/>
<jaxb contextPath="org.example" id="myjaxb"/>
</dataFormats> |
You could then configure a Dozer endpoint to unmarshal the input XML using a JAXB data format and marshal the mapping output using Jackson.
Code Block | ||
---|---|---|
| ||
<endpoint uri="dozer:xml2json?marshalId=myjson&unmarshalId=myjaxb&targetModel=org.example.Order"/> |