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.

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=activemq/camel/trunk/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvRouteTest.java}

... through this route ...

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

... you will end up with this CSV message

No Format
foo,bar

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.

Wiki Markup
{snippet:lang=sql|url=activemq/camel/trunk/components/camel-csv/src/test/resources/daltons.csv}

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

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

The resulting message will contain a List<List<String>>:

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

from("file:salaries.csv").
  unmarshal().csv().
  to("bean:PaymentService?methodName=pay");