The CSV Data Format uses Apache Commons CSV to handle CSV payloads (Comma Separated Values) such as those exported/imported by Excel.







Can be used to set a custom CSVConfig object.



Can be used to set a custom CSVStrategy; the default is CSVStrategy.DEFAULT_STRATEGY.



Whether or not columns are auto-generated in the resulting CSV. The default value is true; subsequent messages use the previously created columns with new fields being added at the end of the line.



Camel 2.4: The column delimiter to use; the default value is ",".



Camel 2.10: Whether or not to skip the first line of CSV input when unmarshalling (e.g. if the content has headers on the first line); the default value is false.

lazyLoadbooleanCamel 2.12.2: Whether or not to Sequential access CSV input through an iterator which could avoid OOM exception when processing huge CSV file; the default value is false
useMapsbooleanCamel 2.13: Whether to use List<Map> when unmarshalling instead of List<List>.

Marshalling a Map to CSV

The component allows you to marshal a Java Map (or any other message type that can be converted in a Map) into a CSV payload.

An example: if you send a message with this map...

... through this route ...

... you will end up with a String containing this CSV message


Sending the Map below through this route will result in a CSV message that looks like foo,bar

Unmarshalling a CSV message into a Java List

Unmarshalling will transform a CSV messsage into a Java List with CSV file lines (containing another List with all the field values).

An example: we have a CSV file with names of persons, their IQ and their current activity.

We can now use the CSV component to unmarshal this file:

The resulting message will contain a List<List<String>> like...

Marshalling a List<Map> to CSV

Available as of Camel 2.1

If you have multiple rows of data you want to be marshalled into CSV format you can now store the message payload as a List<Map<String, Object>> object where the list contains a Map for each row.

File Poller of CSV, then unmarshaling

Given a bean which can handle the incoming data...


... your route then looks as follows

Marshaling with a pipe as delimiter

Using the Spring/XML DSL:

Or the Java DSL:

Using autogenColumns, configRef and strategyRef attributes inside XML DSL

Available as of Camel 2.9.2 / 2.10

You can customize the CSV Data Format to make use of your own CSVConfig and/or CSVStrategy. Also note that the default value of the autogenColumns option is true. The following example should illustrate this customization.

Using skipFirstLine option while unmarshaling

Available as of Camel 2.10

You can instruct the CSV Data Format to skip the first line which contains the CSV headers. Using the Spring/XML DSL:

Or the Java DSL:

Unmarshaling with a pipe as delimiter

Using the Spring/XML DSL:

Or the Java DSL:

Issue in CSVConfig


It looks like that

doesn't work. You have to set the delimiter as a String!


To use CSV in your Camel routes you need to add a dependency on camel-csv, which implements this data format.

If you use Maven you can just add the following to your pom.xml, substituting the version number for the latest and greatest release (see the download page for the latest versions).

© 2004-2014 The Apache Software Foundation.
Apache Camel, Camel, Apache, the Apache feather logo, and the Apache Camel project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
Graphic Design By Hiram