Overview
Converts a List<Map<String, String>> (from the exchange body) into a CSV string.
Input: The exchange body must be a List<Map<String, String>>.
Output: The exchange body is replaced with the CSV string.
Header resolution:
-
If
headeris set, those column names are used (and values are extracted from maps in that order). -
If
headeris not set, the keys of the first map are used.
Split awareness: When forceSkipHeaderWhenPartOfSplit=true (the default) and the exchange has SPLIT_INDEX > 0, the header line is suppressed. This prevents duplicate header lines when marshalling batches that are later appended to a single file.
Properties
|
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
|
Base CSVFormat preset name (e.g. |
|
|
|
|
Field delimiter character. Supports Java escape sequences (e.g. |
|
|
|
(auto-detect) |
Comma-separated list of column names. When omitted, keys from the first map in the body are used. |
|
|
|
|
Whether to omit the header line from output. |
|
|
|
|
Character used to quote field values. |
|
|
|
|
Set to |
|
|
|
(none) |
Apache Commons CSV |
|
|
|
(none) |
Escape character for special characters inside fields. |
|
|
|
(none) |
Character that marks comment lines. |
|
|
|
(none) |
Comma-separated list of comment lines to write before the header. |
|
|
|
Platform default |
Record (line) separator. Accepts tokens |
|
|
|
(none) |
String to write for |
|
|
|
(none) |
Whether to trim leading/trailing whitespace from field values. |
|
|
|
(none) |
Whether to ignore spaces surrounding field values. |
|
|
|
(none) |
Whether to add a trailing delimiter at the end of each record. |
|
|
|
|
Uses the Camel |
|
|
|
|
When |
|
|
|
|
(Advanced) Whether to defer producer creation until the first message is processed. |
Examples
Basic CSV Export
Fetch data from Pricefx and write it as CSV:
<route id="exportToCsv">
<from uri="timer://fetchData?repeatCount=1"/>
<to uri="pfx-api:fetch?filter=myFilter&objectType=PX"/>
<to uri="pfx-csv:marshal"/>
<to uri="file:export?fileName=data.csv"/>
</route>
Semicolon-Delimited with Explicit Quote Mode
Common for European locale CSV files:
<to uri="pfx-csv:marshal?delimiter=;&quoteMode=ALL"/>
Batched Export with Header Only on First Batch
When splitting fetched data into batches and appending to a file, forceSkipHeaderWhenPartOfSplit (default true) ensures the header appears only once:
<route id="batchedExport">
<from uri="timer://fetchData?repeatCount=1"/>
<to uri="pfx-api:fetch?filter=myFilter&objectType=PX&batchedMode=true&batchSize=5000"/>
<split>
<simple>${body}</simple>
<to uri="pfx-api:fetchIterator"/>
<to uri="pfx-csv:marshal"/>
<to uri="file:export?fileName=data.csv&fileExist=Append"/>
</split>
</route>
Custom Record Separator (Windows CRLF)
<to uri="pfx-csv:marshal?recordSeparator=CRLF"/>
Common Pitfalls
-
Delimiter in XML -- Remember to XML-escape the ampersand in URI query strings: use
&not&. For the tab character, use\\t(double-escaped in XML). -
Quoting disabled with embedded delimiters -- Set
quoteDisabled=trueonly if you are certain that no field values contain the delimiter character. When quoting is disabled, fields with embedded delimiters will corrupt the output. -
Null handling -- Without
nullString, null values are written as empty fields. UsenullString=NULLto write the literal stringNULLfor null map values. -
Duplicate headers in batched exports -- If you set
forceSkipHeaderWhenPartOfSplit=falseand marshal inside a split, every batch will include the header line. This produces an invalid CSV when batches are appended to one file.