list-to-csv - Export Data to CSV (DEPRECATED)

This feature is deprecated. It was used actively in IM 1.18.x and older. It is kept now only for compatibility reasons.

This component is used to create CSV formatted file from List<Map<Object,Object>>. The data source can be another PFX component (e.g. jsonToList, xmlToList) and loaded records can be resent to another Camel route. The attributes id and outputUri are required. The component marshals List<Map<Object, Object>> with dataFormat usage if a custom setting is required; or simply specify a parameter delimiter which is used as a column delimiter in the resulting CSV file. In case that the first row with a header is required, you can specify the header parameter which is a list of comma separated column names (order is preserved). If you specify the header but in some cases you do not want to put it to the file (e.g. when appending to the same file), you can switch it off by setting headerDisabled=true. The component also supports mapping via the mapper parameter which can be used for an additional conversion or extending columns with a Groovy or simple expression.

Attributes

Description

Required?

Attributes

Description

Required?

id

ID of the component used for route name.

no

outputUri

Target route of the PFX component where the result will be sent.

yes

dataFormat

Name of the bean with a definition of the CSV file in CsvDataFormat.

no

mapper

Reference to the mapper bean for additional renaming of columns or transformation.

no

batchSize

Size of the batch.

no

completionTimeout

Timeout.

no

headerDisabled

If set to 'true', the resulting CSV will not contain the first line with a header.

no

header

Comma separated list of names for columns. The order will be preserved.

no

delimiter

Column delimiter.

no

injectHeaderFromKeysToFirstLine

Enables a dynamic header (i.e. generated during export to CSV) The header is generated from keys of the first map line from  the list of exported lines.

no


Example of use in camel-context.xml:

<pfx:jsonToList id="jsonToListCsvMapper"> <pfx:listToCsv delimiter=";" header="country,sku,updatedDate,price,manufacturer" outputUri="mock:result" mapper="integrateCsvMapper" /> </pfx:jsonToList> <integrateMapper id="integrateCsvMapper" includeUnmappedProperties="false"> <simple expression="CZ" out="country"/> <body in="sku" out="sku"/> <body in="lastUpdateDate" out="updatedDate"/> <body in="resultPrice" out="price" converter="stringToDecimal" /> <body in="attribute1" out="manufacturer" /> <body in="label" out="label" /> </integrateMapper>

 

Example with dynamic header: 

<bean id="csvDataFormat" class="org.apache.camel.model.dataformat.CsvDataFormat"> <property name="delimiter" value=";"/> </bean> <pfx:list-to-csv id="priceListExport" outputUri="file://${data.directory}/pricelists" injectHeaderFromKeysToFirstLine="true" dataFormat="csvDataFormat"/>

IntegrationManager version 5.8.0