This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-kamelets.git
The following commit(s) were added to refs/heads/main by this push:
new ca835c8d8 Fix #3328: new csv-deserialize-action and
csv-serialize-action Kamelets (#3340)
ca835c8d8 is described below
commit ca835c8d8a678438d68b6f90a2237f7c557ebb7b
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Nov 22 06:25:37 2026 +0100
Fix #3328: new csv-deserialize-action and csv-serialize-action Kamelets
(#3340)
* Fix #3328: new csv-deserialize-action and csv-serialize-action Kamelets
csv-deserialize-action turns CSV text into a List of rows: a Map per row,
keyed by the header line or by given column names, or a List of values
without them. csv-serialize-action turns a List of Maps or Lists, a single
Map, or parsed JSON, into CSV text with a header line, and sets
Content-Type to text/csv. Both are built on the Camel csv data format, with
options for the delimiter, the header line, the column names and the quote
character.
camel-csv writes a header line only for given columns, so without columns
the serialize template writes the keys of the first Map row as the header
line itself. A tab delimiter cannot be given as a kamelet: parameter in a
route, so the descriptions and the tab test set it as a property.
Citrus tests (CsvIT): a round trip, quoted values with the delimiter, quotes
and a line break, a file without a header line, other delimiters and quote
characters, given column names, parsed JSON, empty input, a tab delimiter,
and the failing cases.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
* chore: regenerate the catalog files after merging main
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../camel-kamelets-catalog-sbom.json | 32 +++-
docs/modules/ROOT/nav.adoc | 2 +
kamelets/csv-deserialize-action.kamelet.yaml | 120 +++++++++++++++
kamelets/csv-serialize-action.kamelet.yaml | 161 +++++++++++++++++++++
.../main/resources/META-INF/kamelets-index.json | 20 +++
.../kamelets/csv-deserialize-action.kamelet.yaml | 120 +++++++++++++++
.../kamelets/csv-serialize-action.kamelet.yaml | 161 +++++++++++++++++++++
.../camel-kamelets-itest/src/test/java/CsvIT.java | 33 +++++
.../csv/csv-deserialize-action-route.yaml | 133 +++++++++++++++++
.../csv/csv-deserialize-action.citrus.it.yaml | 67 +++++++++
.../resources/csv/csv-serialize-action-route.yaml | 133 +++++++++++++++++
.../csv/csv-serialize-action.citrus.it.yaml | 67 +++++++++
.../src/test/resources/csv/csv-tab-route.yaml | 30 ++++
.../src/test/resources/csv/csv-tab.citrus.it.yaml | 37 +++++
.../src/test/resources/csv/csv-tab.properties | 20 +++
15 files changed, 1135 insertions(+), 1 deletion(-)
diff --git a/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
b/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
index 94e12d96e..ed0857ff9 100644
--- a/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
+++ b/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
@@ -316,6 +316,16 @@
"type" : "library",
"name" : "crypto-encrypt-action",
"version" : "4.24.0-SNAPSHOT"
+ }, {
+ "bom-ref" : "kamelet:csv-deserialize-action",
+ "type" : "library",
+ "name" : "csv-deserialize-action",
+ "version" : "4.24.0-SNAPSHOT"
+ }, {
+ "bom-ref" : "kamelet:csv-serialize-action",
+ "type" : "library",
+ "name" : "csv-serialize-action",
+ "version" : "4.24.0-SNAPSHOT"
}, {
"bom-ref" : "kamelet:data-type-action",
"type" : "library",
@@ -1499,6 +1509,17 @@
"name" : "camel.apache.org/versioned-by",
"value" : "runtime"
} ]
+ }, {
+ "bom-ref" : "pkg:maven/org.apache.camel/[email protected]",
+ "type" : "library",
+ "group" : "org.apache.camel",
+ "name" : "camel-csv",
+ "version" : "4.24.0-SNAPSHOT",
+ "purl" : "pkg:maven/org.apache.camel/[email protected]",
+ "properties" : [ {
+ "name" : "camel.apache.org/versioned-by",
+ "value" : "runtime"
+ } ]
}, {
"bom-ref" : "pkg:maven/org.apache.camel/[email protected]",
"type" : "library",
@@ -2366,7 +2387,7 @@
} ],
"dependencies" : [ {
"ref" : "camel-kamelets-catalog",
- "dependsOn" : [ "kamelet:avro-deserialize-action",
"kamelet:avro-serialize-action", "kamelet:aws-bedrock-agent-runtime-sink",
"kamelet:aws-bedrock-agent-sink", "kamelet:aws-bedrock-text-sink",
"kamelet:aws-cloudtrail-source", "kamelet:aws-cloudwatch-sink",
"kamelet:aws-comprehend-sink", "kamelet:aws-ddb-sink",
"kamelet:aws-ddb-streams-source", "kamelet:aws-ec2-sink",
"kamelet:aws-eventbridge-sink", "kamelet:aws-eventbridge-source",
"kamelet:aws-kinesis-firehose-sink", "kamelet:aws-ki [...]
+ "dependsOn" : [ "kamelet:avro-deserialize-action",
"kamelet:avro-serialize-action", "kamelet:aws-bedrock-agent-runtime-sink",
"kamelet:aws-bedrock-agent-sink", "kamelet:aws-bedrock-text-sink",
"kamelet:aws-cloudtrail-source", "kamelet:aws-cloudwatch-sink",
"kamelet:aws-comprehend-sink", "kamelet:aws-ddb-sink",
"kamelet:aws-ddb-streams-source", "kamelet:aws-ec2-sink",
"kamelet:aws-eventbridge-sink", "kamelet:aws-eventbridge-source",
"kamelet:aws-kinesis-firehose-sink", "kamelet:aws-ki [...]
}, {
"ref" : "kamelet:avro-deserialize-action",
"dependsOn" : [
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
@@ -2550,6 +2571,12 @@
}, {
"ref" : "kamelet:crypto-encrypt-action",
"dependsOn" : [ "pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
+ }, {
+ "ref" : "kamelet:csv-deserialize-action",
+ "dependsOn" : [ "pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
+ }, {
+ "ref" : "kamelet:csv-serialize-action",
+ "dependsOn" : [ "pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
}, {
"ref" : "kamelet:data-type-action",
"dependsOn" : [ "pkg:maven/org.apache.camel/[email protected]"
]
@@ -3147,6 +3174,9 @@
}, {
"ref" : "pkg:maven/org.apache.camel/[email protected]",
"dependsOn" : [ ]
+ }, {
+ "ref" : "pkg:maven/org.apache.camel/[email protected]",
+ "dependsOn" : [ ]
}, {
"ref" : "pkg:maven/org.apache.camel/[email protected]",
"dependsOn" : [ ]
diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc
index 7256c82c8..4b634cb1b 100644
--- a/docs/modules/ROOT/nav.adoc
+++ b/docs/modules/ROOT/nav.adoc
@@ -60,6 +60,8 @@
* xref:cron-source.adoc[]
* xref:crypto-decrypt-action.adoc[]
* xref:crypto-encrypt-action.adoc[]
+* xref:csv-deserialize-action.adoc[]
+* xref:csv-serialize-action.adoc[]
* xref:data-type-action.adoc[]
* xref:databricks-sink.adoc[]
* xref:databricks-source.adoc[]
diff --git a/kamelets/csv-deserialize-action.kamelet.yaml
b/kamelets/csv-deserialize-action.kamelet.yaml
new file mode 100644
index 000000000..57f6adb6b
--- /dev/null
+++ b/kamelets/csv-deserialize-action.kamelet.yaml
@@ -0,0 +1,120 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+apiVersion: camel.apache.org/v1
+kind: Kamelet
+metadata:
+ name: csv-deserialize-action
+ labels:
+ camel.apache.org/kamelet.type: "action"
+ camel.apache.org/kamelet.verified: "true"
+ annotations:
+ camel.apache.org/kamelet.support.level: "Stable"
+ camel.apache.org/catalog.version: "4.24.0-SNAPSHOT"
+ camel.apache.org/kamelet.icon:
"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sbnM6c29kaXBvZGk9Imh0dHA6Ly9zb2RpcG
[...]
+ camel.apache.org/provider: "Apache Software Foundation"
+ camel.apache.org/kamelet.group: "Actions"
+ camel.apache.org/kamelet.namespace: "Transformation"
+spec:
+ definition:
+ title: "CSV Deserialize Action"
+ description: |-
+ Turns CSV text, such as a file of comma-separated values, into a List of
rows: each row is a Map from the column name to the value, or a List of the
values.
+
+ Use it to work on the records of a CSV file that a source such as
`ftp-source`, `sftp-source` or `aws-s3-source` reads, for example to filter
them or to send them on as JSON with `json-serialize-action`. To write rows as
CSV text, use `csv-serialize-action`.
+
+ Input: CSV text, as text, bytes or a stream; bytes and a stream are read
as UTF-8. The values of a line are separated by `delimiter`. A value that holds
the delimiter, a quote or a line break is put in quotes, with each quote in it
doubled, as in `"Oslo, Norway"` or `"Bob ""B"""`. Lines end with a line feed,
or a carriage return and a line feed.
+
+ Output: the body is a List with one row for each line. With `header`
true (the default) or `columns` set, each row is a Map from the column name to
the value, in the order of the columns, and the header line is not a row.
Otherwise each row is a List of the values. All values are text. The
`Content-Type` header is removed.
+
+ Good to know: a line with fewer values than columns gives a Map without
the missing columns. Empty lines are skipped, unless `skipEmptyLines` is false:
an empty line is then a row with one empty value. Empty text, or only a header
line, gives an empty List. A message without a body, or with a quoted value
that is not closed, fails. The whole text is read into memory. The delimiter
and the quote are one character each. For tab-separated values, set `delimiter`
to a tab in the applic [...]
+ type: object
+ properties:
+ delimiter:
+ title: Delimiter
+ description: "The character that separates the values of a line, such
as `,` or `;`. One character."
+ type: string
+ default: ","
+ example: ";"
+ header:
+ title: Header Line
+ description: "Whether the first line holds the column names. Each row
is then a Map keyed by these names, or by `columns` when it is set. Set it to
false for a file without a header line: each row is then a List of the values,
unless `columns` is set."
+ type: boolean
+ default: true
+ columns:
+ title: Column Names
+ description: "The column names, separated by commas without spaces,
such as `id,name,city`. Each row is then a Map keyed by these names. When
`header` is true, the header line of the file is skipped and these names are
used instead; when `header` is false, every line is a row. A name cannot hold a
comma or a single quote (')."
+ type: string
+ example: "id,name,city"
+ pattern: "^[^']*$"
+ quote:
+ title: Quote Character
+ description: "The character that encloses a value that holds the
delimiter, a quote or a line break. One character."
+ type: string
+ default: '"'
+ skipEmptyLines:
+ title: Skip Empty Lines
+ description: "Whether to skip empty lines. When false, an empty line
is a row with one empty value."
+ type: boolean
+ default: true
+ trim:
+ title: Trim Values
+ description: "Whether to remove the spaces before and after each value
and each column name."
+ type: boolean
+ default: false
+ dataTypes:
+ in:
+ default: text
+ types:
+ text:
+ format: "text-plain"
+ description: "The CSV text, as text, bytes or a stream; bytes and a
stream are read as UTF-8."
+ mediaType: text/plain
+ # No 'default:' here on purpose: no transformer keeps a List of Maps or a
List of Lists as it is. See #3117.
+ out:
+ headers: {}
+ dependencies:
+ - "camel:kamelet"
+ - "camel:csv"
+ template:
+ from:
+ uri: kamelet:source
+ steps:
+ - choice:
+ when:
+ - expression:
+ simple:
+ expression: "'{{header}}' == 'true' || '{{?columns}}' !=
''"
+ steps:
+ - unmarshal:
+ csv:
+ delimiter: "{{delimiter}}"
+ header: "{{?columns}}"
+ ignoreEmptyLines: "{{skipEmptyLines}}"
+ quote: "{{quote}}"
+ skipHeaderRecord: "{{header}}"
+ trim: "{{trim}}"
+ useOrderedMaps: true
+ otherwise:
+ steps:
+ - unmarshal:
+ csv:
+ delimiter: "{{delimiter}}"
+ ignoreEmptyLines: "{{skipEmptyLines}}"
+ quote: "{{quote}}"
+ trim: "{{trim}}"
+ - removeHeader:
+ name: Content-Type
diff --git a/kamelets/csv-serialize-action.kamelet.yaml
b/kamelets/csv-serialize-action.kamelet.yaml
new file mode 100644
index 000000000..0dc41a886
--- /dev/null
+++ b/kamelets/csv-serialize-action.kamelet.yaml
@@ -0,0 +1,161 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+apiVersion: camel.apache.org/v1
+kind: Kamelet
+metadata:
+ name: csv-serialize-action
+ labels:
+ camel.apache.org/kamelet.type: "action"
+ camel.apache.org/kamelet.verified: "true"
+ annotations:
+ camel.apache.org/kamelet.support.level: "Stable"
+ camel.apache.org/catalog.version: "4.24.0-SNAPSHOT"
+ camel.apache.org/kamelet.icon:
"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sbnM6c29kaXBvZGk9Imh0dHA6Ly9zb2RpcG
[...]
+ camel.apache.org/provider: "Apache Software Foundation"
+ camel.apache.org/kamelet.group: "Actions"
+ camel.apache.org/kamelet.namespace: "Transformation"
+spec:
+ definition:
+ title: "CSV Serialize Action"
+ description: |-
+ Turns a List of rows, each a Map from the column name to the value or a
List of the values, into CSV text with a header line of the column names.
+
+ Use it to write records as a CSV file with a sink such as `ftp-sink`,
`sftp-sink` or `aws-s3-sink`, for example the rows that
`csv-deserialize-action` gives, or the JSON that `json-deserialize-action`
parses. To read CSV text, use `csv-deserialize-action`.
+
+ Input: a List of rows, where a row is a Map from the column name to the
value, or a List of the values; a single Map, which is one row; or parsed JSON
(a Jackson `JsonNode`, as `json-deserialize-action` gives): an array of objects
or of arrays, or one object.
+
+ Output: the body is the CSV text, as text, with one line for each row.
Each line ends with a carriage return and a line feed. A value that holds the
delimiter, a quote or a line break is put in quotes, with each quote in it
doubled. When `header` is true (the default), the first line names the columns:
the names in `columns`, or, when it is not set, the keys of the first row if
that row is a Map. Rows that are Lists get no header line unless `columns` is
set. The `Content-Type` hea [...]
+
+ Good to know: with `columns`, each Map row gives the values of these
keys in this order: other keys are left out, and a missing key gives an empty
value. A List row is written as it is. Without `columns`, the columns follow
the keys of the rows, and a key that the first row does not have gets a column
without a name in the header line. A null value is an empty value. A value that
is a Map or a List, such as a nested JSON object, is written as text such as
`\{a=1}` or `[1, 2]`, not [...]
+ type: object
+ properties:
+ delimiter:
+ title: Delimiter
+ description: "The character that separates the values of a line, such
as `,` or `;`. One character."
+ type: string
+ default: ","
+ example: ";"
+ header:
+ title: Header Line
+ description: "Whether to write a first line with the column names: the
names in `columns`, or the keys of the first row when `columns` is not set and
the rows are Maps."
+ type: boolean
+ default: true
+ columns:
+ title: Column Names
+ description: "The columns to write, by name, separated by commas
without spaces, such as `id,name,city`. Each Map row gives the values of these
keys, in this order. A name cannot hold a comma or a single quote (')."
+ type: string
+ example: "id,name,city"
+ pattern: "^[^']*$"
+ quote:
+ title: Quote Character
+ description: "The character that encloses a value that holds the
delimiter, a quote or a line break. One character."
+ type: string
+ default: '"'
+ dataTypes:
+ # No 'default:' here on purpose: no transformer keeps a List or a Map as
it is. See #3117.
+ in:
+ headers: {}
+ # No 'default:' here on purpose: no transformer gives CSV text. See #3117.
+ out:
+ headers:
+ Content-Type:
+ title: Content Type
+ description: "Always `text/csv`."
+ type: string
+ dependencies:
+ - "camel:kamelet"
+ - "camel:csv"
+ - "camel:jackson3"
+ template:
+ from:
+ uri: kamelet:source
+ steps:
+ # parsed JSON, such as json-deserialize-action gives, becomes Maps and
Lists
+ - choice:
+ when:
+ - expression:
+ simple:
+ expression: "${body} is 'tools.jackson.databind.JsonNode'"
+ steps:
+ - unmarshal:
+ json:
+ unmarshalType: java.lang.Object
+ # camel-csv writes a header line only for given columns: take the keys
of the first row
+ - choice:
+ when:
+ - expression:
+ simple:
+ expression: "'{{header}}' == 'true' && '{{?columns}}' ==
'' && ${body} is 'java.util.Map'"
+ steps:
+ - setVariable:
+ name: csvSerializeHeader
+ expression:
+ simple:
+ expression: "${list(${body.keySet()})}"
+ - expression:
+ simple:
+ expression: "'{{header}}' == 'true' && '{{?columns}}' ==
'' && ${body} is 'java.util.List' && ${body.isEmpty()} == false && ${body[0]}
is 'java.util.Map'"
+ steps:
+ - setVariable:
+ name: csvSerializeHeader
+ expression:
+ simple:
+ expression: "${list(${body[0].keySet()})}"
+ - choice:
+ when:
+ - expression:
+ simple:
+ expression: "'{{header}}' == 'true'"
+ steps:
+ - marshal:
+ csv:
+ delimiter: "{{delimiter}}"
+ header: "{{?columns}}"
+ quote: "{{quote}}"
+ otherwise:
+ steps:
+ - marshal:
+ csv:
+ delimiter: "{{delimiter}}"
+ header: "{{?columns}}"
+ quote: "{{quote}}"
+ skipHeaderRecord: true
+ - choice:
+ when:
+ - expression:
+ simple:
+ expression: "${variable.csvSerializeHeader} != null"
+ steps:
+ - marshal:
+ variableSend: csvSerializeHeader
+ variableReceive: csvSerializeHeader
+ csv:
+ delimiter: "{{delimiter}}"
+ quote: "{{quote}}"
+ - setBody:
+ expression:
+ simple:
+ expression: "${variable.csvSerializeHeader}${body}"
+ - removeVariable:
+ name: csvSerializeHeader
+ - convertBodyTo:
+ type: java.lang.String
+ - setHeader:
+ name: Content-Type
+ expression:
+ constant:
+ expression: text/csv
diff --git
a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
index 4ecbda8e2..dd459e456 100644
--- a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
+++ b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
@@ -609,6 +609,26 @@
"group" : "Actions",
"namespace" : "Transformation",
"provider" : "Apache Software Foundation"
+ }, {
+ "name" : "csv-deserialize-action",
+ "type" : "action",
+ "supportLevel" : "Stable",
+ "title" : "CSV Deserialize Action",
+ "summary" : "Turns CSV text, such as a file of comma-separated values,
into a List of rows: each row is a Map from the column name to the value, or a
List of the values.",
+ "description" : "Turns CSV text, such as a file of comma-separated values,
into a List of rows: each row is a Map from the column name to the value, or a
List of the values.\n\nUse it to work on the records of a CSV file that a
source such as `ftp-source`, `sftp-source` or `aws-s3-source` reads, for
example to filter them or to send them on as JSON with `json-serialize-action`.
To write rows as CSV text, use `csv-serialize-action`.\n\nInput: CSV text, as
text, bytes or a stream; byte [...]
+ "group" : "Actions",
+ "namespace" : "Transformation",
+ "provider" : "Apache Software Foundation"
+ }, {
+ "name" : "csv-serialize-action",
+ "type" : "action",
+ "supportLevel" : "Stable",
+ "title" : "CSV Serialize Action",
+ "summary" : "Turns a List of rows, each a Map from the column name to the
value or a List of the values, into CSV text with a header line of the column
names.",
+ "description" : "Turns a List of rows, each a Map from the column name to
the value or a List of the values, into CSV text with a header line of the
column names.\n\nUse it to write records as a CSV file with a sink such as
`ftp-sink`, `sftp-sink` or `aws-s3-sink`, for example the rows that
`csv-deserialize-action` gives, or the JSON that `json-deserialize-action`
parses. To read CSV text, use `csv-deserialize-action`.\n\nInput: a List of
rows, where a row is a Map from the column na [...]
+ "group" : "Actions",
+ "namespace" : "Transformation",
+ "provider" : "Apache Software Foundation"
}, {
"name" : "data-type-action",
"type" : "action",
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/csv-deserialize-action.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/csv-deserialize-action.kamelet.yaml
new file mode 100644
index 000000000..57f6adb6b
--- /dev/null
+++
b/library/camel-kamelets/src/main/resources/kamelets/csv-deserialize-action.kamelet.yaml
@@ -0,0 +1,120 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+apiVersion: camel.apache.org/v1
+kind: Kamelet
+metadata:
+ name: csv-deserialize-action
+ labels:
+ camel.apache.org/kamelet.type: "action"
+ camel.apache.org/kamelet.verified: "true"
+ annotations:
+ camel.apache.org/kamelet.support.level: "Stable"
+ camel.apache.org/catalog.version: "4.24.0-SNAPSHOT"
+ camel.apache.org/kamelet.icon:
"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sbnM6c29kaXBvZGk9Imh0dHA6Ly9zb2RpcG
[...]
+ camel.apache.org/provider: "Apache Software Foundation"
+ camel.apache.org/kamelet.group: "Actions"
+ camel.apache.org/kamelet.namespace: "Transformation"
+spec:
+ definition:
+ title: "CSV Deserialize Action"
+ description: |-
+ Turns CSV text, such as a file of comma-separated values, into a List of
rows: each row is a Map from the column name to the value, or a List of the
values.
+
+ Use it to work on the records of a CSV file that a source such as
`ftp-source`, `sftp-source` or `aws-s3-source` reads, for example to filter
them or to send them on as JSON with `json-serialize-action`. To write rows as
CSV text, use `csv-serialize-action`.
+
+ Input: CSV text, as text, bytes or a stream; bytes and a stream are read
as UTF-8. The values of a line are separated by `delimiter`. A value that holds
the delimiter, a quote or a line break is put in quotes, with each quote in it
doubled, as in `"Oslo, Norway"` or `"Bob ""B"""`. Lines end with a line feed,
or a carriage return and a line feed.
+
+ Output: the body is a List with one row for each line. With `header`
true (the default) or `columns` set, each row is a Map from the column name to
the value, in the order of the columns, and the header line is not a row.
Otherwise each row is a List of the values. All values are text. The
`Content-Type` header is removed.
+
+ Good to know: a line with fewer values than columns gives a Map without
the missing columns. Empty lines are skipped, unless `skipEmptyLines` is false:
an empty line is then a row with one empty value. Empty text, or only a header
line, gives an empty List. A message without a body, or with a quoted value
that is not closed, fails. The whole text is read into memory. The delimiter
and the quote are one character each. For tab-separated values, set `delimiter`
to a tab in the applic [...]
+ type: object
+ properties:
+ delimiter:
+ title: Delimiter
+ description: "The character that separates the values of a line, such
as `,` or `;`. One character."
+ type: string
+ default: ","
+ example: ";"
+ header:
+ title: Header Line
+ description: "Whether the first line holds the column names. Each row
is then a Map keyed by these names, or by `columns` when it is set. Set it to
false for a file without a header line: each row is then a List of the values,
unless `columns` is set."
+ type: boolean
+ default: true
+ columns:
+ title: Column Names
+ description: "The column names, separated by commas without spaces,
such as `id,name,city`. Each row is then a Map keyed by these names. When
`header` is true, the header line of the file is skipped and these names are
used instead; when `header` is false, every line is a row. A name cannot hold a
comma or a single quote (')."
+ type: string
+ example: "id,name,city"
+ pattern: "^[^']*$"
+ quote:
+ title: Quote Character
+ description: "The character that encloses a value that holds the
delimiter, a quote or a line break. One character."
+ type: string
+ default: '"'
+ skipEmptyLines:
+ title: Skip Empty Lines
+ description: "Whether to skip empty lines. When false, an empty line
is a row with one empty value."
+ type: boolean
+ default: true
+ trim:
+ title: Trim Values
+ description: "Whether to remove the spaces before and after each value
and each column name."
+ type: boolean
+ default: false
+ dataTypes:
+ in:
+ default: text
+ types:
+ text:
+ format: "text-plain"
+ description: "The CSV text, as text, bytes or a stream; bytes and a
stream are read as UTF-8."
+ mediaType: text/plain
+ # No 'default:' here on purpose: no transformer keeps a List of Maps or a
List of Lists as it is. See #3117.
+ out:
+ headers: {}
+ dependencies:
+ - "camel:kamelet"
+ - "camel:csv"
+ template:
+ from:
+ uri: kamelet:source
+ steps:
+ - choice:
+ when:
+ - expression:
+ simple:
+ expression: "'{{header}}' == 'true' || '{{?columns}}' !=
''"
+ steps:
+ - unmarshal:
+ csv:
+ delimiter: "{{delimiter}}"
+ header: "{{?columns}}"
+ ignoreEmptyLines: "{{skipEmptyLines}}"
+ quote: "{{quote}}"
+ skipHeaderRecord: "{{header}}"
+ trim: "{{trim}}"
+ useOrderedMaps: true
+ otherwise:
+ steps:
+ - unmarshal:
+ csv:
+ delimiter: "{{delimiter}}"
+ ignoreEmptyLines: "{{skipEmptyLines}}"
+ quote: "{{quote}}"
+ trim: "{{trim}}"
+ - removeHeader:
+ name: Content-Type
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/csv-serialize-action.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/csv-serialize-action.kamelet.yaml
new file mode 100644
index 000000000..0dc41a886
--- /dev/null
+++
b/library/camel-kamelets/src/main/resources/kamelets/csv-serialize-action.kamelet.yaml
@@ -0,0 +1,161 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+apiVersion: camel.apache.org/v1
+kind: Kamelet
+metadata:
+ name: csv-serialize-action
+ labels:
+ camel.apache.org/kamelet.type: "action"
+ camel.apache.org/kamelet.verified: "true"
+ annotations:
+ camel.apache.org/kamelet.support.level: "Stable"
+ camel.apache.org/catalog.version: "4.24.0-SNAPSHOT"
+ camel.apache.org/kamelet.icon:
"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sbnM6c29kaXBvZGk9Imh0dHA6Ly9zb2RpcG
[...]
+ camel.apache.org/provider: "Apache Software Foundation"
+ camel.apache.org/kamelet.group: "Actions"
+ camel.apache.org/kamelet.namespace: "Transformation"
+spec:
+ definition:
+ title: "CSV Serialize Action"
+ description: |-
+ Turns a List of rows, each a Map from the column name to the value or a
List of the values, into CSV text with a header line of the column names.
+
+ Use it to write records as a CSV file with a sink such as `ftp-sink`,
`sftp-sink` or `aws-s3-sink`, for example the rows that
`csv-deserialize-action` gives, or the JSON that `json-deserialize-action`
parses. To read CSV text, use `csv-deserialize-action`.
+
+ Input: a List of rows, where a row is a Map from the column name to the
value, or a List of the values; a single Map, which is one row; or parsed JSON
(a Jackson `JsonNode`, as `json-deserialize-action` gives): an array of objects
or of arrays, or one object.
+
+ Output: the body is the CSV text, as text, with one line for each row.
Each line ends with a carriage return and a line feed. A value that holds the
delimiter, a quote or a line break is put in quotes, with each quote in it
doubled. When `header` is true (the default), the first line names the columns:
the names in `columns`, or, when it is not set, the keys of the first row if
that row is a Map. Rows that are Lists get no header line unless `columns` is
set. The `Content-Type` hea [...]
+
+ Good to know: with `columns`, each Map row gives the values of these
keys in this order: other keys are left out, and a missing key gives an empty
value. A List row is written as it is. Without `columns`, the columns follow
the keys of the rows, and a key that the first row does not have gets a column
without a name in the header line. A null value is an empty value. A value that
is a Map or a List, such as a nested JSON object, is written as text such as
`\{a=1}` or `[1, 2]`, not [...]
+ type: object
+ properties:
+ delimiter:
+ title: Delimiter
+ description: "The character that separates the values of a line, such
as `,` or `;`. One character."
+ type: string
+ default: ","
+ example: ";"
+ header:
+ title: Header Line
+ description: "Whether to write a first line with the column names: the
names in `columns`, or the keys of the first row when `columns` is not set and
the rows are Maps."
+ type: boolean
+ default: true
+ columns:
+ title: Column Names
+ description: "The columns to write, by name, separated by commas
without spaces, such as `id,name,city`. Each Map row gives the values of these
keys, in this order. A name cannot hold a comma or a single quote (')."
+ type: string
+ example: "id,name,city"
+ pattern: "^[^']*$"
+ quote:
+ title: Quote Character
+ description: "The character that encloses a value that holds the
delimiter, a quote or a line break. One character."
+ type: string
+ default: '"'
+ dataTypes:
+ # No 'default:' here on purpose: no transformer keeps a List or a Map as
it is. See #3117.
+ in:
+ headers: {}
+ # No 'default:' here on purpose: no transformer gives CSV text. See #3117.
+ out:
+ headers:
+ Content-Type:
+ title: Content Type
+ description: "Always `text/csv`."
+ type: string
+ dependencies:
+ - "camel:kamelet"
+ - "camel:csv"
+ - "camel:jackson3"
+ template:
+ from:
+ uri: kamelet:source
+ steps:
+ # parsed JSON, such as json-deserialize-action gives, becomes Maps and
Lists
+ - choice:
+ when:
+ - expression:
+ simple:
+ expression: "${body} is 'tools.jackson.databind.JsonNode'"
+ steps:
+ - unmarshal:
+ json:
+ unmarshalType: java.lang.Object
+ # camel-csv writes a header line only for given columns: take the keys
of the first row
+ - choice:
+ when:
+ - expression:
+ simple:
+ expression: "'{{header}}' == 'true' && '{{?columns}}' ==
'' && ${body} is 'java.util.Map'"
+ steps:
+ - setVariable:
+ name: csvSerializeHeader
+ expression:
+ simple:
+ expression: "${list(${body.keySet()})}"
+ - expression:
+ simple:
+ expression: "'{{header}}' == 'true' && '{{?columns}}' ==
'' && ${body} is 'java.util.List' && ${body.isEmpty()} == false && ${body[0]}
is 'java.util.Map'"
+ steps:
+ - setVariable:
+ name: csvSerializeHeader
+ expression:
+ simple:
+ expression: "${list(${body[0].keySet()})}"
+ - choice:
+ when:
+ - expression:
+ simple:
+ expression: "'{{header}}' == 'true'"
+ steps:
+ - marshal:
+ csv:
+ delimiter: "{{delimiter}}"
+ header: "{{?columns}}"
+ quote: "{{quote}}"
+ otherwise:
+ steps:
+ - marshal:
+ csv:
+ delimiter: "{{delimiter}}"
+ header: "{{?columns}}"
+ quote: "{{quote}}"
+ skipHeaderRecord: true
+ - choice:
+ when:
+ - expression:
+ simple:
+ expression: "${variable.csvSerializeHeader} != null"
+ steps:
+ - marshal:
+ variableSend: csvSerializeHeader
+ variableReceive: csvSerializeHeader
+ csv:
+ delimiter: "{{delimiter}}"
+ quote: "{{quote}}"
+ - setBody:
+ expression:
+ simple:
+ expression: "${variable.csvSerializeHeader}${body}"
+ - removeVariable:
+ name: csvSerializeHeader
+ - convertBodyTo:
+ type: java.lang.String
+ - setHeader:
+ name: Content-Type
+ expression:
+ constant:
+ expression: text/csv
diff --git a/tests/camel-kamelets-itest/src/test/java/CsvIT.java
b/tests/camel-kamelets-itest/src/test/java/CsvIT.java
new file mode 100644
index 000000000..a3845bc70
--- /dev/null
+++ b/tests/camel-kamelets-itest/src/test/java/CsvIT.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.stream.Stream;
+
+import org.citrusframework.api.common.TestLoader;
+import org.citrusframework.junit.jupiter.CitrusSupport;
+import org.citrusframework.junit.jupiter.CitrusTestFactory;
+import org.citrusframework.junit.jupiter.CitrusTestFactorySupport;
+import org.junit.jupiter.api.DynamicTest;
+
+@CitrusSupport
+public class CsvIT {
+
+ @CitrusTestFactory
+ public Stream<DynamicTest> csv() {
+ return
CitrusTestFactorySupport.factory(TestLoader.YAML).packageScan("csv");
+ }
+}
diff --git
a/tests/camel-kamelets-itest/src/test/resources/csv/csv-deserialize-action-route.yaml
b/tests/camel-kamelets-itest/src/test/resources/csv/csv-deserialize-action-route.yaml
new file mode 100644
index 000000000..e0b9c5dbc
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/csv/csv-deserialize-action-route.yaml
@@ -0,0 +1,133 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+# CSV text in, a List of rows out: the rows are logged as JSON text, so a line
break in a value shows as \n
+- route:
+ from:
+ uri: "timer:header"
+ parameters:
+ repeatCount: 1
+ steps:
+ # a header line; a quoted value with the delimiter, with doubled
quotes and with a line break;
+ # an empty line; a line with fewer values than columns; non-ASCII
text, as bytes
+ - setBody:
+ constant: "id,name,city\r\n1,Zoë,\"Oslo, Norway\"\r\n\r\n2,\"Bob
\"\"B\"\"\",\"line1\nline2\"\r\n3,Eve\r\n"
+ - convertBodyTo:
+ type: "byte[]"
+ - setHeader:
+ name: Content-Type
+ constant: text/csv
+ - to: "kamelet:csv-deserialize-action"
+ - setVariable:
+ name: rowType
+ simple: "${body.getClass().getName()} of
${body[0].getClass().getName()}, ${body.size()} rows, ct=${header.Content-Type}"
+ - to: "kamelet:json-serialize-action"
+ - log: "Header ${variable.rowType}: ${bodyAs(String)}"
+# No header line: each row is a List of the values
+- route:
+ from:
+ uri: "timer:headerless"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: "1,Ann,Oslo\n2,Bob,Bergen\n"
+ - to:
+ uri: "kamelet:csv-deserialize-action"
+ parameters:
+ header: false
+ - log: "Headerless ${body.getClass().getName()} of
${body[0].getClass().getName()}: ${body}"
+# Another delimiter, the column names given for a file without a header line,
and trimmed values
+- route:
+ from:
+ uri: "timer:columns"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: "1; Ann ;Oslo\n2;Bob; Bergen\n"
+ - to:
+ uri: "kamelet:csv-deserialize-action"
+ parameters:
+ header: false
+ columns: "id,name,city"
+ delimiter: ";"
+ trim: true
+ - log: "Columns ${body}"
+# The column names given for a file with a header line: they replace it
+- route:
+ from:
+ uri: "timer:rename"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: "a,b\n1,Ann\n"
+ - to:
+ uri: "kamelet:csv-deserialize-action"
+ parameters:
+ columns: "id,name"
+ - log: "Rename ${body}"
+# Another quote character, and empty lines kept
+- route:
+ from:
+ uri: "timer:quote"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: "id,name\n\n1,'Ann, A'\n"
+ - to:
+ uri: "kamelet:csv-deserialize-action"
+ parameters:
+ quote: "'"
+ skipEmptyLines: false
+ - log: "Quote ${body}"
+# Empty text, and only a header line, give an empty List
+- route:
+ from:
+ uri: "timer:empty"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: ""
+ - to: "kamelet:csv-deserialize-action"
+ - setVariable:
+ name: empty
+ simple: "${body.getClass().getName()} ${body}"
+ - setBody:
+ constant: "id,name\n"
+ - to: "kamelet:csv-deserialize-action"
+ - log: "Empty ${variable.empty}, header only ${body}"
+# A quoted value that is not closed fails the message
+- route:
+ from:
+ uri: "timer:unclosed"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: "id,name\n1,\"Ann\n"
+ - doTry:
+ steps:
+ - to: "kamelet:csv-deserialize-action"
+ - log: "Accepted ${body}"
+ doCatch:
+ - exception:
+ - "java.lang.Exception"
+ steps:
+ - log: "Rejected ${exception.getClass().getName()}:
${exception.message}"
diff --git
a/tests/camel-kamelets-itest/src/test/resources/csv/csv-deserialize-action.citrus.it.yaml
b/tests/camel-kamelets-itest/src/test/resources/csv/csv-deserialize-action.citrus.it.yaml
new file mode 100644
index 000000000..6ed789b40
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/csv/csv-deserialize-action.citrus.it.yaml
@@ -0,0 +1,67 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+
+name: csv-deserialize-action-test
+actions:
+ - camel:
+ cli:
+ run:
+ integration:
+ file: "csv/csv-deserialize-action-route.yaml"
+ # A header line: each row is a Map in the order of the columns, with the
quoted values unquoted; the empty line
+ # is skipped, the short line has no city, the bytes are read as UTF-8, and
the Content-Type header is removed
+ - camel:
+ cli:
+ verify:
+ integration: "csv-deserialize-action-route"
+ logMessage: 'Header java.util.ArrayList of java.util.LinkedHashMap,
3 rows, ct=: [{"id":"1","name":"Zoë","city":"Oslo,
Norway"},{"id":"2","name":"Bob
\"B\"","city":"line1\nline2"},{"id":"3","name":"Eve"}]'
+ # No header line: each row is a List of the values
+ - camel:
+ cli:
+ verify:
+ integration: "csv-deserialize-action-route"
+ logMessage: 'Headerless java.util.ArrayList of java.util.ArrayList:
[[1, Ann, Oslo], [2, Bob, Bergen]]'
+ # The delimiter ;, given column names for a file without a header line, and
trimmed values
+ - camel:
+ cli:
+ verify:
+ integration: "csv-deserialize-action-route"
+ logMessage: 'Columns [{id=1, name=Ann, city=Oslo}, {id=2, name=Bob,
city=Bergen}]'
+ # Given column names replace the header line of the file
+ - camel:
+ cli:
+ verify:
+ integration: "csv-deserialize-action-route"
+ logMessage: 'Rename [{id=1, name=Ann}]'
+ # The quote character ', and an empty line kept as a row with one empty value
+ - camel:
+ cli:
+ verify:
+ integration: "csv-deserialize-action-route"
+ logMessage: 'Quote [{id=}, {id=1, name=Ann, A}]'
+ # Empty text, and only a header line, give an empty List
+ - camel:
+ cli:
+ verify:
+ integration: "csv-deserialize-action-route"
+ logMessage: 'Empty java.util.ArrayList [], header only []'
+ # A quoted value that is not closed fails the message
+ - camel:
+ cli:
+ verify:
+ integration: "csv-deserialize-action-route"
+ logMessage: 'Rejected java.io.UncheckedIOException:
org.apache.commons.csv.CSVException: (startline 2) EOF reached before
encapsulated token finished'
diff --git
a/tests/camel-kamelets-itest/src/test/resources/csv/csv-serialize-action-route.yaml
b/tests/camel-kamelets-itest/src/test/resources/csv/csv-serialize-action-route.yaml
new file mode 100644
index 000000000..2c503ea3f
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/csv/csv-serialize-action-route.yaml
@@ -0,0 +1,133 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+# Rows in, CSV text out: the text is logged with <CR> and <LF> for the line
ends, so a line break shows
+# Round trip: the CSV text read with csv-deserialize-action and written back
is the same text
+- route:
+ from:
+ uri: "timer:roundtrip"
+ parameters:
+ repeatCount: 1
+ steps:
+ # trim: false keeps the line break at the end of the text
+ - setBody:
+ constant:
+ expression: "id,name,city\r\n1,Zoë,\"Oslo, Norway\"\r\n2,\"Bob
\"\"B\"\"\",\"line1\nline2\"\r\n"
+ trim: false
+ - setVariable:
+ name: original
+ simple: "${body}"
+ - to: "kamelet:csv-deserialize-action"
+ - to: "kamelet:csv-serialize-action"
+ - choice:
+ when:
+ - simple: "${body} == ${variable.original}"
+ steps:
+ - setVariable:
+ name: same
+ constant: "true"
+ - log: "Roundtrip ${body.getClass().getName()}
ct=${header.Content-Type} same=${variable.same}: ${body.replace('\r',
'<CR>').replace('\n', '<LF>')}"
+# A single Map is one row, with a header line of its keys
+- route:
+ from:
+ uri: "timer:map"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ simple: "${map(id,1,name,Ann)}"
+ - to: "kamelet:csv-serialize-action"
+ - log: "Map ${body.replace('\r', '<CR>').replace('\n', '<LF>')}"
+# Given columns: their order, a key that is not one of them is left out, a
missing key is empty; no header line
+- route:
+ from:
+ uri: "timer:columns"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ simple:
"${list(${map(id,1,name,Ann,city,Oslo)},${map(id,2,name,Bob)})}"
+ - to:
+ uri: "kamelet:csv-serialize-action"
+ parameters:
+ columns: "city,id"
+ header: false
+ - log: "Columns ${body.replace('\r', '<CR>').replace('\n', '<LF>')}"
+# Rows that are Lists, another delimiter and another quote character: no
header line without columns
+- route:
+ from:
+ uri: "timer:lists"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ simple: "${list(${list(1,Ann;A)},${list(2,Bob)})}"
+ - to:
+ uri: "kamelet:csv-serialize-action"
+ parameters:
+ delimiter: ";"
+ quote: "'"
+ - log: "Lists ${body.replace('\r', '<CR>').replace('\n', '<LF>')}"
+# Parsed JSON: an array of objects, with a nested object, a null and a key
that the first row does not have
+- route:
+ from:
+ uri: "timer:json"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant:
'[{"id":1,"name":"Ann","tags":{"a":1},"note":null},{"id":2,"name":"Bob","extra":true}]'
+ - to: "kamelet:json-deserialize-action"
+ - to: "kamelet:csv-serialize-action"
+ - log: "Json ${body.replace('\r', '<CR>').replace('\n', '<LF>')}"
+# An empty List gives empty text, or only the header line with columns
+- route:
+ from:
+ uri: "timer:empty"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ simple: "${list()}"
+ - to: "kamelet:csv-serialize-action"
+ - setVariable:
+ name: empty
+ simple: "[${body}]"
+ - setBody:
+ simple: "${list()}"
+ - to:
+ uri: "kamelet:csv-serialize-action"
+ parameters:
+ columns: "id,name"
+ - log: "Empty ${variable.empty}, with columns ${body.replace('\r',
'<CR>').replace('\n', '<LF>')}"
+# A body of text fails the message
+- route:
+ from:
+ uri: "timer:text"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: "hello"
+ - doTry:
+ steps:
+ - to: "kamelet:csv-serialize-action"
+ - log: "Accepted ${body}"
+ doCatch:
+ - exception:
+ - "java.lang.Exception"
+ steps:
+ - log: "Rejected ${exception.getClass().getName()}:
${exception.message}"
diff --git
a/tests/camel-kamelets-itest/src/test/resources/csv/csv-serialize-action.citrus.it.yaml
b/tests/camel-kamelets-itest/src/test/resources/csv/csv-serialize-action.citrus.it.yaml
new file mode 100644
index 000000000..36186bca2
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/csv/csv-serialize-action.citrus.it.yaml
@@ -0,0 +1,67 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+
+name: csv-serialize-action-test
+actions:
+ - camel:
+ cli:
+ run:
+ integration:
+ file: "csv/csv-serialize-action-route.yaml"
+ # Round trip: the text, as a String, is the text that csv-deserialize-action
read, and the Content-Type is text/csv
+ - camel:
+ cli:
+ verify:
+ integration: "csv-serialize-action-route"
+ logMessage: 'Roundtrip java.lang.String ct=text/csv same=true:
id,name,city<CR><LF>1,Zoë,"Oslo, Norway"<CR><LF>2,"Bob
""B""","line1<LF>line2"<CR><LF>'
+ # A single Map: a header line of its keys and one row
+ - camel:
+ cli:
+ verify:
+ integration: "csv-serialize-action-route"
+ logMessage: 'Map id,name<CR><LF>1,Ann<CR><LF>'
+ # Given columns without a header line: their order, other keys left out, a
missing key empty
+ - camel:
+ cli:
+ verify:
+ integration: "csv-serialize-action-route"
+ logMessage: 'Columns Oslo,1<CR><LF>,2<CR><LF>'
+ # List rows, the delimiter ; and the quote character ': no header line
+ - camel:
+ cli:
+ verify:
+ integration: "csv-serialize-action-route"
+ logMessage: "Lists 1;'Ann;A'<CR><LF>2;Bob<CR><LF>"
+ # Parsed JSON: the keys of the first row are the header line; a nested
object is text, a null is empty,
+ # and the key that only the second row has gets a column without a name
+ - camel:
+ cli:
+ verify:
+ integration: "csv-serialize-action-route"
+ logMessage: 'Json
id,name,tags,note<CR><LF>1,Ann,{a=1},<CR><LF>2,Bob,,,true<CR><LF>'
+ # An empty List: empty text, or only the header line with columns
+ - camel:
+ cli:
+ verify:
+ integration: "csv-serialize-action-route"
+ logMessage: 'Empty [], with columns id,name<CR><LF>'
+ # A body of text fails the message
+ - camel:
+ cli:
+ verify:
+ integration: "csv-serialize-action-route"
+ logMessage: 'Rejected
org.apache.camel.NoTypeConversionAvailableException: No type converter
available to convert from type: java.lang.String to the required type:
java.util.List'
diff --git
a/tests/camel-kamelets-itest/src/test/resources/csv/csv-tab-route.yaml
b/tests/camel-kamelets-itest/src/test/resources/csv/csv-tab-route.yaml
new file mode 100644
index 000000000..f97a09c08
--- /dev/null
+++ b/tests/camel-kamelets-itest/src/test/resources/csv/csv-tab-route.yaml
@@ -0,0 +1,30 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+# Tab-separated values: csv-tab.properties sets the delimiter of both Kamelets
to a tab,
+# as a parameter of the Kamelet in a route cannot hold a tab
+- route:
+ from:
+ uri: "timer:tab"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: "id\tname\n1\tAnn, A\n"
+ - to: "kamelet:csv-deserialize-action"
+ - log: "Tab rows ${body}"
+ - to: "kamelet:csv-serialize-action"
+ - log: "Tab text ${body.replace('\t', '<TAB>').replace('\r',
'<CR>').replace('\n', '<LF>')}"
diff --git
a/tests/camel-kamelets-itest/src/test/resources/csv/csv-tab.citrus.it.yaml
b/tests/camel-kamelets-itest/src/test/resources/csv/csv-tab.citrus.it.yaml
new file mode 100644
index 000000000..3d0659269
--- /dev/null
+++ b/tests/camel-kamelets-itest/src/test/resources/csv/csv-tab.citrus.it.yaml
@@ -0,0 +1,37 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+
+name: csv-tab-test
+actions:
+ # A tab as delimiter, set as a property in csv-tab.properties: it cannot be
given as a parameter of the Kamelet in a route
+ - camel:
+ cli:
+ run:
+ resources:
+ - "csv-tab.properties"
+ integration:
+ file: "csv/csv-tab-route.yaml"
+ - camel:
+ cli:
+ verify:
+ integration: "csv-tab-route"
+ logMessage: 'Tab rows [{id=1, name=Ann, A}]'
+ - camel:
+ cli:
+ verify:
+ integration: "csv-tab-route"
+ logMessage: 'Tab text id<TAB>name<CR><LF>1<TAB>Ann, A<CR><LF>'
diff --git
a/tests/camel-kamelets-itest/src/test/resources/csv/csv-tab.properties
b/tests/camel-kamelets-itest/src/test/resources/csv/csv-tab.properties
new file mode 100644
index 000000000..dd5fc96ca
--- /dev/null
+++ b/tests/camel-kamelets-itest/src/test/resources/csv/csv-tab.properties
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# A tab as the delimiter of both Kamelets: \t is a tab in a properties file
+camel.kamelet.csv-deserialize-action.delimiter=\t
+camel.kamelet.csv-serialize-action.delimiter=\t