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 717357f43 chore: csv-serialize-action writes the header line with 
headerFromMapKeys, and columns may have spaces (CAMEL-27371) (#3354)
717357f43 is described below

commit 717357f4301578c2594fbe48fb0f1e73496eef43
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Nov 22 17:25:26 2026 +0100

    chore: csv-serialize-action writes the header line with headerFromMapKeys, 
and columns may have spaces (CAMEL-27371) (#3354)
    
    * chore: csv-serialize-action writes the header line with 
headerFromMapKeys, and columns may have spaces and single quotes (CAMEL-27371)
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
    
    * chore: regenerate the catalog index
    
    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]>
---
 kamelets/csv-serialize-action.kamelet.yaml         | 46 ++--------------------
 .../main/resources/META-INF/kamelets-index.json    |  2 +-
 .../kamelets/csv-serialize-action.kamelet.yaml     | 46 ++--------------------
 .../resources/csv/csv-serialize-action-route.yaml  | 15 +++++++
 .../csv/csv-serialize-action.citrus.it.yaml        | 13 ++++--
 5 files changed, 34 insertions(+), 88 deletions(-)

diff --git a/kamelets/csv-serialize-action.kamelet.yaml 
b/kamelets/csv-serialize-action.kamelet.yaml
index 0dc41a886..085784b24 100644
--- a/kamelets/csv-serialize-action.kamelet.yaml
+++ b/kamelets/csv-serialize-action.kamelet.yaml
@@ -40,7 +40,7 @@ spec:
 
       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  [...]
+      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 keys of the first 
row, when it is a Map, are the columns of all the rows in the same way: a key 
that only a later row has is left out, and a key that a later row does not have 
gives an empty value. A null value is an empty value. A value that is a Map or 
a List, such as a nest [...]
     type: object
     properties:
       delimiter:
@@ -56,10 +56,9 @@ spec:
         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 (')."
+        description: "The columns to write, by name, separated by commas, such 
as `id,name,city`. Spaces around a name are left out, so `id, name` is the same 
as `id,name`. Each Map row gives the values of these keys, in this order. A 
name cannot hold a comma."
         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."
@@ -94,27 +93,7 @@ spec:
                   - 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()})}"
+        # without columns, the keys of the first Map row are the header line 
and the columns of all the rows
         - choice:
             when:
               - expression:
@@ -125,6 +104,7 @@ spec:
                       csv:
                         delimiter: "{{delimiter}}"
                         header: "{{?columns}}"
+                        headerFromMapKeys: true
                         quote: "{{quote}}"
             otherwise:
               steps:
@@ -134,24 +114,6 @@ spec:
                       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:
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 3483afa8e..e2bf43214 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
@@ -625,7 +625,7 @@
     "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 [...]
+    "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"
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
index 0dc41a886..085784b24 100644
--- 
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
@@ -40,7 +40,7 @@ spec:
 
       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  [...]
+      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 keys of the first 
row, when it is a Map, are the columns of all the rows in the same way: a key 
that only a later row has is left out, and a key that a later row does not have 
gives an empty value. A null value is an empty value. A value that is a Map or 
a List, such as a nest [...]
     type: object
     properties:
       delimiter:
@@ -56,10 +56,9 @@ spec:
         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 (')."
+        description: "The columns to write, by name, separated by commas, such 
as `id,name,city`. Spaces around a name are left out, so `id, name` is the same 
as `id,name`. Each Map row gives the values of these keys, in this order. A 
name cannot hold a comma."
         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."
@@ -94,27 +93,7 @@ spec:
                   - 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()})}"
+        # without columns, the keys of the first Map row are the header line 
and the columns of all the rows
         - choice:
             when:
               - expression:
@@ -125,6 +104,7 @@ spec:
                       csv:
                         delimiter: "{{delimiter}}"
                         header: "{{?columns}}"
+                        headerFromMapKeys: true
                         quote: "{{quote}}"
             otherwise:
               steps:
@@ -134,24 +114,6 @@ spec:
                       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:
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
index 2c503ea3f..c6a3238e9 100644
--- 
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
@@ -93,6 +93,21 @@
         - to: "kamelet:json-deserialize-action"
         - to: "kamelet:csv-serialize-action"
         - log: "Json ${body.replace('\r', '<CR>').replace('\n', '<LF>')}"
+# Columns with spaces after the commas, and a name with a single quote
+- route:
+    from:
+      uri: "timer:spaces"
+      parameters:
+        repeatCount: 1
+      steps:
+        - setBody:
+            constant: '[{"id":1,"owner''s name":"Ann","city":"Oslo"}]'
+        - to: "kamelet:json-deserialize-action"
+        - to:
+            uri: "kamelet:csv-serialize-action"
+            parameters:
+              columns: "owner's name, id"
+        - log: "Spaces ${body.replace('\r', '<CR>').replace('\n', '<LF>')}"
 # An empty List gives empty text, or only the header line with columns
 - route:
     from:
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
index 36186bca2..76c531bb2 100644
--- 
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
@@ -46,13 +46,20 @@ actions:
         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
+  # Parsed JSON: the keys of the first row are the header line and the columns 
of all the rows; a nested object
+  # is text, a null is empty, the keys the second row does not have are empty, 
and the key that only it has is
+  # left out
   - 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>'
+          logMessage: 'Json 
id,name,tags,note<CR><LF>1,Ann,{a=1},<CR><LF>2,Bob,,<CR><LF>'
+  # Spaces around the names of columns are left out, and a name can hold a 
single quote
+  - camel:
+      cli:
+        verify:
+          integration: "csv-serialize-action-route"
+          logMessage: "Spaces owner's name,id<CR><LF>Ann,1<CR><LF>"
   # An empty List: empty text, or only the header line with columns
   - camel:
       cli:

Reply via email to