Skip to main content

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:

  1. 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.

  2. Transform the CSV message into a list of maps by unmarshalling with useMaps option set to true

  3. Call the csvDecimalFormatChangeProcessor process.

  4. Transform the list of maps back into CSV by marshalling with useMaps set to true.

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>