Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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

...

As of Camel 2.15.0, it now uses the Apache Commons CSV 1.1 which is based on a completely different set of options.

Available options until Camel 2.15

Option

Type

Description

config

CSVConfig

Can be used to set a custom CSVConfig object.

strategy

CSVStrategy

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

autogenColumns

boolean

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.

delimiter

String

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

skipFirstLine

boolean

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

Available options as of Camel 2.15

OptionTypeDescription
formatCSVFormatThe reference format to use, it will be updated with the other format options, the default value is CSVFormat.DEFAULT
formatNameString

Used in order to initialize the reference format using the name of one of the default formats.

The possible values are: "DEFAULT", "RFC4180", "EXCEL", "TDF", "MYSQL"

commentMarkerCharacter

Overrides the comment marker of the reference format.

This option is null by default. When null it keeps the value of the reference format which is null for CSVFormat.DEFAULT.

delimiterCharacter

Overrides the delimiter of the reference format.

This option is null by defaut. When null it keeps the value of the reference format which is ',' for CSVFormat.DEFAULT.

escapeDisabledboolean

Disables the escape character of the reference format.

This option is false by default.

escapeCharacter

Overrides the escape character of the reference format.

This option is null by default. When null it keeps the value of the reference format which is null for CSVFormat.DEFAULT.

headerDisabledboolean

Disables the header of the reference format.

This option is false by default.

headerString[]

Overrides the header of the reference format.

This option is null by default. When null it keeps the value of the reference format which is null for CSVFormat.DEFAULT.

In the XML DSL, this option is configured using children <header> tags:

Code Block
languagexml
<csv formatRef="excelFormat" delimiter="|" skipHeaderRecord="true">
    <header>orderId</header>
    <header>amount</header>
</csv>
allowMissingColumnNamesBoolean

Overrides the missing column names behavior of the reference format.

This option is null by default. When null it keeps the value of the reference format which is false for CSVFormat.DEFAULT.

ignoreEmptyLinesBoolean

Overrides the empty line behavior of the reference format.

This option is null by default. When null it keeps the value of the reference format which is true for CSVFormat.DEFAULT.

ignoreSurroundingSpacesBoolean

Overrides the surrounding spaces behavior of the reference format.

This option is null by default. When null it keeps the value of the reference format which is false for CSVFormat.DEFAULT.

nullStringDisabledboolean

Disables the null string representation of the reference format.

This option is false by default.

nullStringString

Overrides the null string representation of the reference format.

This option is null by default. When null it keeps the value of the reference format which is null for CSVFormat.DEFAULT.

quoteDisabledboolean

Disables the quote of the reference format.

This option is false by default.

quoteCharacter

Overrides the quote symbol of the reference format.

This option is null by default. When null it keeps the value of the reference format which is '"' (double quote) for CSVFormat.DEFAULT.

quoteModeQuoteMode

Overrides the quote mode of the reference format.

This option is null by default. When null it keeps the value of the reference format which is null for CSVFormat.DEFAULT.

recordSeparatorDisabledboolean

Disables the record separator of the reference format.

This option is false by default.

recordSeparatorString

Overrides the record separator of the reference format.

This option is null by default. When null it keeps the value of the reference format which is \r\n (CRLF) for CSVFormat.DEFAULT.

skipHeaderRecordBoolean

Overrides the header record behavior of the reference format.

This option is null by default. When null it keeps the value of the reference format which is false for CSVFormat.DEFAULT.

lazyLoadboolean

Whether the unmarshalling should produce an iterator that reads the lines on the fly or if all the lines must be read at one.

This option is false by default.

useMapsboolean

Whether the unmarshalling should produce maps for the lines values instead of lists. It requires to have header (either defined or collected).

This options is false by default.

recordConverterCsvRecordConverter

Sets the record converter to use. If defines the useMaps options is disabled.

This option is null by default.

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

 

Wiki Markup
{snippet:id=marshalInput|lang=java|url=camel/trunk/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvRouteTest.java}

...