Change CSV decimal separator in a Camel route
Most FA readers expect CSV files to use point as a decimal separator. If your file uses a different separator, you can change it by using Camel CSV decimal format change processor included in FA Connector.
To use the processor in your Camel route:
Set the following headers:
CamelCSVOriginalDecimalSeparator
and the original CSV separator as its value.CamelCSVNewDecimalSeparator
and the new CSV separator as its value.CamelCSVFieldsToReplace
and the fields you want the change to apply to as its value.
Transform the CSV message into a list of maps by unmarshalling with
useMaps
option set totrue
.Call the
csvDecimalFormatChangeProcessor
process.Transform the list of maps back into CSV by marshalling with
useMaps
set totrue
.
Example of using CSV decimal format change processor
<setHeader name="CamelCSVOriginalDecimalSeparator"> <simple> <![CDATA[,]]> </simple> </setHeader> <setHeader name="CamelCSVNewDecimalSeparator"> <simple> <![CDATA[.]]> </simple> </setHeader> <setHeader name="CamelCSVFieldsToReplace"> <simple> <![CDATA[amount]]> </simple> </setHeader> <unmarshal><csv useMaps="true" delimiter=";"/></unmarshal> <process ref="csvDecimalFormatChangeProcessor"/> <marshal><csv useMaps="true" delimiter=";"/></marshal>