Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added documentation for a custom delimiter

...

Option

Type

Description

config

CSVConfig

Can be used to set a custom CSVConfig object.

strategy

CSVStrategy

Camel uses by default CSVStrategy.DEFAULT_STRATEGY.

autogenColumn

boolean

Camel 1.6.1/2.0: Is default true. By default, columns are autogenerated in the resulting CSV. Subsequent messages use the previously created columns with new fields being added at the end of the line.

delimiter

String

Camel 2.4: Is default ,. Can be used to configure the delimiter, if it's not the comma.

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.

...

Code Block
xml
xml
<route>
        <!-- poll every 10 seconds -->
        <from uri="file:///some/path/to/pickup/csvfiles?delete=true&amp;consumer.delay=10000" />
        <unmarshal><csv /></unmarshal>
        <to uri="bean:myCsvHandler?method=doHandleCsvData" />
</route>

Marshaling with a pipe as delimiter

Using the Spring/XML DSL:

Code Block
xml
xml

<route>
  <from uri="direct:start" />
  <marshal>
    <csv delimiter="|" />
  </marshal>
  <to uri="bean:myCsvHandler?method=doHandleCsv" />
</route>

Or the Java DSL:

Code Block

CsvDataFormat csv = new CsvDataFormat();
CSVConfig config = new CSVConfig();
config.setDelimiter('|');
csv.setConfig(config);

from("direct:start")
  .marshal(csv)
  .convertBodyTo(String.class)
.to("bean:myCsvHandler?method=doHandleCsv");
Code Block

CsvDataFormat csv = new CsvDataFormat();
csv.setDelimiter("|");

from("direct:start")
  .marshal(csv)
  .convertBodyTo(String.class)
.to("bean:myCsvHandler?method=doHandleCsv");

Unmarshaling with a pipe as delimiter

Using the Spring/XML DSL:

Code Block
xml
xml

<route>
  <from uri="direct:start" />
  <unmarshal>
    <csv delimiter="|" />
  </unmarshal>
  <to uri="bean:myCsvHandler?method=doHandleCsv" />
</route>

Or the Java DSL:

Code Block

CsvDataFormat csv = new CsvDataFormat();
CSVStrategy strategy = CSVStrategy.DEFAULT_STRATEGY;
strategy.setDelimiter('|');
csv.setStrategy(strategy);

from("direct:start")
  .unmarshal(csv)
.to("bean:myCsvHandler?method=doHandleCsv");
Code Block

CsvDataFormat csv = new CsvDataFormat();
csv.setDelimiter("|");

from("direct:start")
  .unmarshal(csv)
.to("bean:myCsvHandler?method=doHandleCsv");

Dependencies

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

...