Using dozer for Java Bean to Bean mapping in Apache Camel - makes life extremely simple to recursively copy data from one object to another.
The below steps will help to quickly add a dozer mapping file in OSGI Blueprint xml
The below steps will help to quickly add a dozer mapping file in OSGI Blueprint xml
- In the blueprint.xml add the bean definitions below
Note - the name of the camel context should be same as the argument index="0"
<bean id="dozerConverterLoader" class="org.apache.camel.converter.dozer.DozerTypeConverterLoader"> <argument index="0" ref="abcdCamelContext" /> <argument index="1" ref="abcMapper" /> </bean> <bean id="abcMapper" class="org.apache.camel.converter.dozer.DozerBeanMapperConfiguration" />
- Inside the route include the sample code to invoke the dozer mapping file.
- Also mention the expected source object / destination object
<camelContext id="abcdCamelContext" xmlns="http://camel.apache.org/schema/blueprint"> <route> <from uri="direct:test" />
.....
<to uri="dozer:submitRequest?mappingFile=mapping/abcd.xml&sourceModel=com.abcd.SourceReq&targetModel=com.abcd.DestReq" />
.....
</route>
</camelContext>
- Mapping file - location - under src/main/resources
- Mapping file - sample
- Please follow the dozer documentation for complex beans.
<mappings xmlns="http://dozer.sourceforge.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://dozer.sourceforge.net http://dozer.sourceforge.net/schema/beanmapping.xsd"> <mapping wildcard="false"> <class-a>com.abcd.SourceReq</class-a> <class-b>com.abcd.DestReq</class-b> <field> <a>caseNumberSrc</a> <b>caseNumberDest</b> </field>
</mapping>
</mappings>
- Sample Source Object - SourceReq
public class SourceReq { String caseNumberSrc; public String getCaseNumberSrc() { return caseNumberSrc; } public void setCaseNumberSrc(String caseNumberSrc) { this.caseNumberSrc = caseNumberSrc; } }
- Sample Destination Object - DestReq
public class DestReq { String caseNumberDest; public String getCaseNumberDest() { return caseNumberDest; } public void setCaseNumberDest(String caseNumberDest) { this.caseNumberDest = caseNumberDest; } }
No comments:
Post a Comment