Overview
Type converters transform field values from one data type to another during mapping. Integration Manager provides built-in converters for common transformations like String-to-Decimal, String-to-Date, and String-to-Integer.
There are two ways to use converters:
-
converterExpression— references a built-in converter by name (no configuration needed) -
converter— references a Spring bean by ID (built-ins auto-registered; custom converters defined inbeans/folder)
Complete XML Examples
Using converterExpression (Recommended for Built-ins)
The simplest way. No bean definitions needed — just reference the converter by name:
<mappers>
<loadMapper id="productMapper">
<body in="sku" out="sku"/>
<body in="price" out="attribute1" converterExpression="stringToDecimal"/>
<body in="quantity" out="attribute2" converterExpression="stringToInteger"/>
<body in="lastModified" out="attribute3" converterExpression="stringToDate"/>
</loadMapper>
</mappers>
Using converter with Pre-Registered Bean Names
Built-in converters are also available as pre-registered Spring beans — reference by name with the converter attribute:
<mappers>
<loadMapper id="productMapper">
<body in="price" out="attribute1" converter="stringToDecimal"/>
<body in="quantity" out="attribute2" converter="stringToInteger"/>
<body in="cost" out="attribute3" converter="stringToNumber"/>
<body in="lastModified" out="attribute4" converter="stringToDate"/>
</loadMapper>
</mappers>
Locale-Aware Decimal Conversion
For decimal formats that vary by locale (e.g., 1.234,56 in German vs 1,234.56 in English), pass the locale code in parentheses with converterExpression:
<mappers>
<loadMapper id="localeAwareMapper">
<!-- German locale: expects comma as decimal separator -->
<body in="germanPrice" out="attribute1" converterExpression="stringToDecimal(de)"/>
<!-- French locale: expects comma as decimal separator -->
<body in="frenchPrice" out="attribute2" converterExpression="stringToDecimal(fr)"/>
<!-- US locale (default behavior): expects dot as decimal separator -->
<body in="usPrice" out="attribute3" converterExpression="stringToDecimal(en)"/>
</loadMapper>
</mappers>
Custom Converter (StringRight) via beans/ Folder
For converters that require constructor arguments (like StringRight), define the bean in the beans/ directory — not inline in the mapper file:
beans/converters.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="stringRight7"
class="net.pricefx.integration.mapper.converter.StringRight">
<constructor-arg value="7"/>
</bean>
</beans>
mappers/product-mapper.xml:
<mappers>
<loadMapper id="productMapper">
<body in="sku" converter="stringRight7"/>
<body in="name" out="label"/>
</loadMapper>
</mappers>
How It Works
-
converterExpression— references a built-in converter by name. Supports optional locale in parentheses, e.g.,stringToDecimal(de). No bean definition needed. -
converter— references a Spring bean ID. Built-in converters are auto-registered by the IM framework. Custom converters must be defined in a file underbeans/. -
Built-in converter names:
-
stringToDecimal— converts string to BigDecimal -
stringToNumber— converts string to Number -
stringToInteger— converts string to Integer -
stringToDate— converts string to Date
-
-
Converters are applied after the field value is read but before it is written to the output.
Common Pitfalls
-
Locale mismatch: If your source data uses German number format (
1.234,56) but you do not specify the(de)locale, the conversion will fail or produce incorrect results. -
convertervsconverterExpression:converterExpressionuses built-in converters directly.converteruses Spring bean IDs. Do not use a bean name inconverterExpression— it will not find it. -
Custom converters go in
beans/: Never define<beans:bean>elements inside a mapper file. Custom converter beans belong in thebeans/directory as separate Spring XML files. -
Null values: If the source field is null, converters may throw exceptions. Use a
<groovy>expression with null checks for fields that might be empty. -
includeUnmappedProperties: Whenfalse, only explicitly mapped fields appear in the output. Whentrue(default), all source fields pass through.