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.git
The following commit(s) were added to refs/heads/main by this push:
new 76d66eafb8af CAMEL-27371: camel-csv - write a header line from the Map
keys, trim the names of the header option, and a CSV hint for a null body
(#30588)
76d66eafb8af is described below
commit 76d66eafb8afab30252709f2a5aa1741b9d50ba7
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Nov 22 11:44:45 2026 +0100
CAMEL-27371: camel-csv - write a header line from the Map keys, trim the
names of the header option, and a CSV hint for a null body (#30588)
- New option headerFromMapKeys: when marshalling a Map, or a List (or an
Iterator) of Maps, without a configured header, the marshaller writes a
header line with the keys of the first Map, and these keys are the columns
of all the rows (as with the header option). The common case is JSON rows
turned into CSV.
- The names of the header option are trimmed, so "id, name" gives the
columns id and name, not " name".
- Unmarshalling a null body said "setBody with constant:
resource:file:data.json", a JSON hint in a CSV error. The unmarshal
processor now passes the data format name to BodyFacts, and the hint names
a file of that data format (data.csv, data.tsv, data.xml, data.yaml), or
data.json as before when the data format is not known.
The new model option is regenerated in the xml-io, yaml-io and java-io
readers and writers, the YAML DSL deserializers and schemas, and the
catalog (models, dataformats, XSDs, YAML model schema, docs).
- camel-csv - MapKeysHeaderMarshaller uses the format of the parent, and
says that its getMapRecordValues is never called
The marshaller kept its own copy of the format, which shadowed the field of
the parent: the parent now has a protected getFormat(). getMapRecordValues
is
only there because it is abstract in the parent (marshal hands every body to
another marshaller), so it throws UnsupportedOperationException instead of
holding code that never runs.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
.../org/apache/camel/catalog/dataformats/csv.json | 41 +++---
.../apache/camel/catalog/docs/csv-dataformat.adoc | 76 +++++++++-
.../org/apache/camel/catalog/models/csv.json | 41 +++---
.../apache/camel/catalog/schemas/camel-spring.xsd | 11 ++
.../apache/camel/catalog/schemas/camel-xml-io.xsd | 11 ++
.../camel/catalog/schemas/camelYamlDsl-model.json | 50 ++++---
.../dataformat/csv/CsvDataFormatConfigurer.java | 7 +
.../org/apache/camel/dataformat/csv/csv.json | 41 +++---
.../camel-csv/src/main/docs/csv-dataformat.adoc | 76 +++++++++-
.../apache/camel/dataformat/csv/CsvDataFormat.java | 37 ++++-
.../apache/camel/dataformat/csv/CsvMarshaller.java | 97 +++++++++++++
.../dataformat/csv/CsvHeaderNamesTrimTest.java | 97 +++++++++++++
.../csv/CsvMarshalHeaderFromMapKeysTest.java | 153 +++++++++++++++++++++
.../dataformat/csv/CsvUnmarshalNullBodyTest.java | 59 ++++++++
.../org/apache/camel/model/dataformat/csv.json | 41 +++---
.../camel/model/dataformat/CsvDataFormat.java | 38 +++++
.../reifier/dataformat/CsvDataFormatReifier.java | 1 +
.../org/apache/camel/support/BodyFactsTest.java | 16 +++
.../apache/camel/java/out/JavaDslModelWriter.java | 1 +
.../java/org/apache/camel/support/BodyFacts.java | 39 +++++-
.../support/processor/UnmarshalProcessor.java | 2 +-
.../java/org/apache/camel/xml/in/ModelParser.java | 1 +
.../java/org/apache/camel/xml/out/ModelWriter.java | 1 +
.../org/apache/camel/yaml/out/YamlModelWriter.java | 1 +
.../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 6 +
.../dsl/yaml/deserializers/ModelDeserializers.java | 6 +
.../resources/schema/camelYamlDsl-canonical.json | 6 +
.../resources/schema/camelYamlDsl-model.json | 50 ++++---
.../generated/resources/schema/camelYamlDsl.json | 6 +
29 files changed, 878 insertions(+), 134 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/csv.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/csv.json
index 2b073a8fdfe2..727f0703e14d 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/csv.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/csv.json
@@ -31,25 +31,26 @@
"escape": { "index": 6, "kind": "attribute", "displayName": "Escape",
"group": "advanced", "label": "advanced", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "description": "Sets the escape character to use." },
"headerDisabled": { "index": 7, "kind": "attribute", "displayName":
"Header Disabled", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to disable
headers." },
"header": { "index": 8, "kind": "attribute", "displayName": "Header",
"group": "common", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "To configure the CSV headers. Multiple headers can be separated
by comma." },
- "allowMissingColumnNames": { "index": 9, "kind": "attribute",
"displayName": "Allow Missing Column Names", "group": "common", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to allow missing column names." },
- "ignoreEmptyLines": { "index": 10, "kind": "attribute", "displayName":
"Ignore Empty Lines", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to ignore empty
lines." },
- "ignoreSurroundingSpaces": { "index": 11, "kind": "attribute",
"displayName": "Ignore Surrounding Spaces", "group": "common", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to ignore surrounding spaces." },
- "nullStringDisabled": { "index": 12, "kind": "attribute", "displayName":
"Null String Disabled", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to disable null string handling." },
- "nullString": { "index": 13, "kind": "attribute", "displayName": "Null
String", "group": "advanced", "label": "advanced", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "description": "Sets the null string." },
- "quoteDisabled": { "index": 14, "kind": "attribute", "displayName": "Quote
Disabled", "group": "common", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether to disable quoting." },
- "quote": { "index": 15, "kind": "attribute", "displayName": "Quote",
"group": "common", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "The quote character to use. The default is double-quote
character." },
- "recordSeparatorDisabled": { "index": 16, "kind": "attribute",
"displayName": "Record Separator Disabled", "group": "advanced", "label":
"advanced", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether to disable the record
separator." },
- "recordSeparator": { "index": 17, "kind": "attribute", "displayName":
"Record Separator", "group": "common", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "description": "The record separator (aka new line) which by
default is new line characters (CRLF)." },
- "skipHeaderRecord": { "index": 18, "kind": "attribute", "displayName":
"Skip Header Record", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to skip the
header record in the output." },
- "quoteMode": { "index": 19, "kind": "attribute", "displayName": "Quote
Mode", "group": "common", "required": false, "type": "enum", "javaType":
"java.lang.String", "enum": [ "ALL", "ALL_NON_NULL", "MINIMAL", "NON_NUMERIC",
"NONE" ], "deprecated": false, "autowired": false, "secret": false,
"description": "Sets the quote mode." },
- "ignoreHeaderCase": { "index": 20, "kind": "attribute", "displayName":
"Ignore Header Case", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to ignore case
when accessing header names." },
- "trim": { "index": 21, "kind": "attribute", "displayName": "Trim",
"group": "common", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether to trim leading and trailing
blanks." },
- "trailingDelimiter": { "index": 22, "kind": "attribute", "displayName":
"Trailing Delimiter", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to add a
trailing delimiter." },
- "marshallerFactoryRef": { "index": 23, "kind": "attribute", "displayName":
"Marshaller Factory Ref", "group": "advanced", "label": "advanced", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "Sets the implementation of
the CsvMarshallerFactory interface which is able to customize
marshalling\/unmarshalling behavior." },
- "lazyLoad": { "index": 24, "kind": "attribute", "displayName": "Lazy
Load", "group": "advanced", "label": "advanced", "required": false, "type":
"boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "description": "Whether the
unmarshalling should produce an iterator that reads the lines on the fly or if
all the lines must be read at one." },
- "useMaps": { "index": 25, "kind": "attribute", "displayName": "Use Maps",
"group": "common", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the unmarshalling should produce
maps (HashMap) for the lines values instead of lists. It requires to have
header (either defined or collected)." },
- "useOrderedMaps": { "index": 26, "kind": "attribute", "displayName": "Use
Ordered Maps", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether the
unmarshalling should produce ordered maps (LinkedHashMap) for the lines values
instead of lists. It requires to have header (either defined or collected)." },
- "recordConverterRef": { "index": 27, "kind": "attribute", "displayName":
"Record Converter Ref", "group": "advanced", "label": "advanced", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "Refers to a custom
CsvRecordConverter to lookup from the registry to use." },
- "captureHeaderRecord": { "index": 28, "kind": "attribute", "displayName":
"Capture Header Record", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether the unmarshalling should capture the header record and store it in the
message header." }
+ "headerFromMapKeys": { "index": 9, "kind": "attribute", "displayName":
"Header From Map Keys", "group": "common", "required": false, "type":
"boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "description": "When marshalling
a Map, or a List of Maps, and no header is configured, whether to write a
header line with the keys of the first Map. The keys of the first Map are then
the columns of all the rows, as with [...]
+ "allowMissingColumnNames": { "index": 10, "kind": "attribute",
"displayName": "Allow Missing Column Names", "group": "common", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to allow missing column names." },
+ "ignoreEmptyLines": { "index": 11, "kind": "attribute", "displayName":
"Ignore Empty Lines", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to ignore empty
lines." },
+ "ignoreSurroundingSpaces": { "index": 12, "kind": "attribute",
"displayName": "Ignore Surrounding Spaces", "group": "common", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to ignore surrounding spaces." },
+ "nullStringDisabled": { "index": 13, "kind": "attribute", "displayName":
"Null String Disabled", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to disable null string handling." },
+ "nullString": { "index": 14, "kind": "attribute", "displayName": "Null
String", "group": "advanced", "label": "advanced", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "description": "Sets the null string." },
+ "quoteDisabled": { "index": 15, "kind": "attribute", "displayName": "Quote
Disabled", "group": "common", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether to disable quoting." },
+ "quote": { "index": 16, "kind": "attribute", "displayName": "Quote",
"group": "common", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "The quote character to use. The default is double-quote
character." },
+ "recordSeparatorDisabled": { "index": 17, "kind": "attribute",
"displayName": "Record Separator Disabled", "group": "advanced", "label":
"advanced", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether to disable the record
separator." },
+ "recordSeparator": { "index": 18, "kind": "attribute", "displayName":
"Record Separator", "group": "common", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "description": "The record separator (aka new line) which by
default is new line characters (CRLF)." },
+ "skipHeaderRecord": { "index": 19, "kind": "attribute", "displayName":
"Skip Header Record", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to skip the
header record in the output." },
+ "quoteMode": { "index": 20, "kind": "attribute", "displayName": "Quote
Mode", "group": "common", "required": false, "type": "enum", "javaType":
"java.lang.String", "enum": [ "ALL", "ALL_NON_NULL", "MINIMAL", "NON_NUMERIC",
"NONE" ], "deprecated": false, "autowired": false, "secret": false,
"description": "Sets the quote mode." },
+ "ignoreHeaderCase": { "index": 21, "kind": "attribute", "displayName":
"Ignore Header Case", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to ignore case
when accessing header names." },
+ "trim": { "index": 22, "kind": "attribute", "displayName": "Trim",
"group": "common", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether to trim leading and trailing
blanks." },
+ "trailingDelimiter": { "index": 23, "kind": "attribute", "displayName":
"Trailing Delimiter", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to add a
trailing delimiter." },
+ "marshallerFactoryRef": { "index": 24, "kind": "attribute", "displayName":
"Marshaller Factory Ref", "group": "advanced", "label": "advanced", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "Sets the implementation of
the CsvMarshallerFactory interface which is able to customize
marshalling\/unmarshalling behavior." },
+ "lazyLoad": { "index": 25, "kind": "attribute", "displayName": "Lazy
Load", "group": "advanced", "label": "advanced", "required": false, "type":
"boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "description": "Whether the
unmarshalling should produce an iterator that reads the lines on the fly or if
all the lines must be read at one." },
+ "useMaps": { "index": 26, "kind": "attribute", "displayName": "Use Maps",
"group": "common", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the unmarshalling should produce
maps (HashMap) for the lines values instead of lists. It requires to have
header (either defined or collected)." },
+ "useOrderedMaps": { "index": 27, "kind": "attribute", "displayName": "Use
Ordered Maps", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether the
unmarshalling should produce ordered maps (LinkedHashMap) for the lines values
instead of lists. It requires to have header (either defined or collected)." },
+ "recordConverterRef": { "index": 28, "kind": "attribute", "displayName":
"Record Converter Ref", "group": "advanced", "label": "advanced", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "Refers to a custom
CsvRecordConverter to lookup from the registry to use." },
+ "captureHeaderRecord": { "index": 29, "kind": "attribute", "displayName":
"Capture Header Record", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether the unmarshalling should capture the header record and store it in the
message header." }
}
}
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/csv-dataformat.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/csv-dataformat.adoc
index c8fe3efceb67..c286e67f6a26 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/csv-dataformat.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/csv-dataformat.adoc
@@ -183,7 +183,8 @@ format, you can now store the message payload as a
each row.
When `header` is set (and `headerDisabled` is false), its names are the
-columns, in that order. Otherwise, the columns are the keys of the first Map,
+columns, in that order (the names are trimmed, so `id, name` gives the
+columns `id` and `name`). Otherwise, the columns are the keys of the first Map,
followed by the keys of later Maps that the first one does not have, in the
order they first appear (the rows written before such a key appears have
fewer fields). A Map without one of these keys gets a null value in that
@@ -202,6 +203,79 @@ that each have keys of their own (such as sparse or
pivoted data) gives
about N²/2 fields for N rows; for such data, convert the rows to Lists, or
set `header` to only the columns you need.
+==== Writing a header line from the keys of the first Map
+
+*Since Camel 4.24*
+
+Set `headerFromMapKeys` to write a header line with the keys of the first
+Map when no `header` is configured, such as when turning JSON rows into CSV:
+
+[tabs]
+====
+Java::
++
+[source,java]
+----
+CsvDataFormat csv = new CsvDataFormat();
+csv.setHeaderFromMapKeys(true);
+
+from("direct:start")
+ .unmarshal().json()
+ .marshal(csv)
+ .to("file:out?fileName=rows.csv");
+----
+
+XML::
++
+[source,xml]
+----
+<route>
+ <from uri="direct:start"/>
+ <unmarshal>
+ <json/>
+ </unmarshal>
+ <marshal>
+ <csv headerFromMapKeys="true"/>
+ </marshal>
+ <to uri="file:out?fileName=rows.csv"/>
+</route>
+----
+
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:start
+ steps:
+ - unmarshal:
+ json: {}
+ - marshal:
+ csv:
+ headerFromMapKeys: true
+ - to:
+ uri: file:out
+ parameters:
+ fileName: rows.csv
+----
+====
+
+The JSON `[{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}]` is then
+written as:
+
+----
+id,name
+1,Alice
+2,Bob
+----
+
+The keys of the first Map are the columns of all the rows, as if they were
+given with `header`: a row without one of these keys gets an empty field, and
+a key that only later rows have is not written. A body whose first row is not
+a Map (such as a List of Lists) gets no header line, and `skipHeaderRecord`
+leaves the header line out.
+
=== File Poller of CSV, then unmarshaling
Given a bean which can handle the incoming data...
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/csv.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/csv.json
index 557f4f550279..e0c608d32d77 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/csv.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/csv.json
@@ -22,25 +22,26 @@
"escape": { "index": 6, "kind": "attribute", "displayName": "Escape",
"group": "advanced", "label": "advanced", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "description": "Sets the escape character to use." },
"headerDisabled": { "index": 7, "kind": "attribute", "displayName":
"Header Disabled", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to disable
headers." },
"header": { "index": 8, "kind": "attribute", "displayName": "Header",
"group": "common", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "To configure the CSV headers. Multiple headers can be separated
by comma." },
- "allowMissingColumnNames": { "index": 9, "kind": "attribute",
"displayName": "Allow Missing Column Names", "group": "common", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to allow missing column names." },
- "ignoreEmptyLines": { "index": 10, "kind": "attribute", "displayName":
"Ignore Empty Lines", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to ignore empty
lines." },
- "ignoreSurroundingSpaces": { "index": 11, "kind": "attribute",
"displayName": "Ignore Surrounding Spaces", "group": "common", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to ignore surrounding spaces." },
- "nullStringDisabled": { "index": 12, "kind": "attribute", "displayName":
"Null String Disabled", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to disable null string handling." },
- "nullString": { "index": 13, "kind": "attribute", "displayName": "Null
String", "group": "advanced", "label": "advanced", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "description": "Sets the null string." },
- "quoteDisabled": { "index": 14, "kind": "attribute", "displayName": "Quote
Disabled", "group": "common", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether to disable quoting." },
- "quote": { "index": 15, "kind": "attribute", "displayName": "Quote",
"group": "common", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "The quote character to use. The default is double-quote
character." },
- "recordSeparatorDisabled": { "index": 16, "kind": "attribute",
"displayName": "Record Separator Disabled", "group": "advanced", "label":
"advanced", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether to disable the record
separator." },
- "recordSeparator": { "index": 17, "kind": "attribute", "displayName":
"Record Separator", "group": "common", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "description": "The record separator (aka new line) which by
default is new line characters (CRLF)." },
- "skipHeaderRecord": { "index": 18, "kind": "attribute", "displayName":
"Skip Header Record", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to skip the
header record in the output." },
- "quoteMode": { "index": 19, "kind": "attribute", "displayName": "Quote
Mode", "group": "common", "required": false, "type": "enum", "javaType":
"java.lang.String", "enum": [ "ALL", "ALL_NON_NULL", "MINIMAL", "NON_NUMERIC",
"NONE" ], "deprecated": false, "autowired": false, "secret": false,
"description": "Sets the quote mode." },
- "ignoreHeaderCase": { "index": 20, "kind": "attribute", "displayName":
"Ignore Header Case", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to ignore case
when accessing header names." },
- "trim": { "index": 21, "kind": "attribute", "displayName": "Trim",
"group": "common", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether to trim leading and trailing
blanks." },
- "trailingDelimiter": { "index": 22, "kind": "attribute", "displayName":
"Trailing Delimiter", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to add a
trailing delimiter." },
- "marshallerFactoryRef": { "index": 23, "kind": "attribute", "displayName":
"Marshaller Factory Ref", "group": "advanced", "label": "advanced", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "Sets the implementation of
the CsvMarshallerFactory interface which is able to customize
marshalling\/unmarshalling behavior." },
- "lazyLoad": { "index": 24, "kind": "attribute", "displayName": "Lazy
Load", "group": "advanced", "label": "advanced", "required": false, "type":
"boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "description": "Whether the
unmarshalling should produce an iterator that reads the lines on the fly or if
all the lines must be read at one." },
- "useMaps": { "index": 25, "kind": "attribute", "displayName": "Use Maps",
"group": "common", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the unmarshalling should produce
maps (HashMap) for the lines values instead of lists. It requires to have
header (either defined or collected)." },
- "useOrderedMaps": { "index": 26, "kind": "attribute", "displayName": "Use
Ordered Maps", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether the
unmarshalling should produce ordered maps (LinkedHashMap) for the lines values
instead of lists. It requires to have header (either defined or collected)." },
- "recordConverterRef": { "index": 27, "kind": "attribute", "displayName":
"Record Converter Ref", "group": "advanced", "label": "advanced", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "Refers to a custom
CsvRecordConverter to lookup from the registry to use." },
- "captureHeaderRecord": { "index": 28, "kind": "attribute", "displayName":
"Capture Header Record", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether the unmarshalling should capture the header record and store it in the
message header." }
+ "headerFromMapKeys": { "index": 9, "kind": "attribute", "displayName":
"Header From Map Keys", "group": "common", "required": false, "type":
"boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "description": "When marshalling
a Map, or a List of Maps, and no header is configured, whether to write a
header line with the keys of the first Map. The keys of the first Map are then
the columns of all the rows, as with [...]
+ "allowMissingColumnNames": { "index": 10, "kind": "attribute",
"displayName": "Allow Missing Column Names", "group": "common", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to allow missing column names." },
+ "ignoreEmptyLines": { "index": 11, "kind": "attribute", "displayName":
"Ignore Empty Lines", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to ignore empty
lines." },
+ "ignoreSurroundingSpaces": { "index": 12, "kind": "attribute",
"displayName": "Ignore Surrounding Spaces", "group": "common", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to ignore surrounding spaces." },
+ "nullStringDisabled": { "index": 13, "kind": "attribute", "displayName":
"Null String Disabled", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to disable null string handling." },
+ "nullString": { "index": 14, "kind": "attribute", "displayName": "Null
String", "group": "advanced", "label": "advanced", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "description": "Sets the null string." },
+ "quoteDisabled": { "index": 15, "kind": "attribute", "displayName": "Quote
Disabled", "group": "common", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether to disable quoting." },
+ "quote": { "index": 16, "kind": "attribute", "displayName": "Quote",
"group": "common", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "The quote character to use. The default is double-quote
character." },
+ "recordSeparatorDisabled": { "index": 17, "kind": "attribute",
"displayName": "Record Separator Disabled", "group": "advanced", "label":
"advanced", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether to disable the record
separator." },
+ "recordSeparator": { "index": 18, "kind": "attribute", "displayName":
"Record Separator", "group": "common", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "description": "The record separator (aka new line) which by
default is new line characters (CRLF)." },
+ "skipHeaderRecord": { "index": 19, "kind": "attribute", "displayName":
"Skip Header Record", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to skip the
header record in the output." },
+ "quoteMode": { "index": 20, "kind": "attribute", "displayName": "Quote
Mode", "group": "common", "required": false, "type": "enum", "javaType":
"java.lang.String", "enum": [ "ALL", "ALL_NON_NULL", "MINIMAL", "NON_NUMERIC",
"NONE" ], "deprecated": false, "autowired": false, "secret": false,
"description": "Sets the quote mode." },
+ "ignoreHeaderCase": { "index": 21, "kind": "attribute", "displayName":
"Ignore Header Case", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to ignore case
when accessing header names." },
+ "trim": { "index": 22, "kind": "attribute", "displayName": "Trim",
"group": "common", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether to trim leading and trailing
blanks." },
+ "trailingDelimiter": { "index": 23, "kind": "attribute", "displayName":
"Trailing Delimiter", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to add a
trailing delimiter." },
+ "marshallerFactoryRef": { "index": 24, "kind": "attribute", "displayName":
"Marshaller Factory Ref", "group": "advanced", "label": "advanced", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "Sets the implementation of
the CsvMarshallerFactory interface which is able to customize
marshalling\/unmarshalling behavior." },
+ "lazyLoad": { "index": 25, "kind": "attribute", "displayName": "Lazy
Load", "group": "advanced", "label": "advanced", "required": false, "type":
"boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "description": "Whether the
unmarshalling should produce an iterator that reads the lines on the fly or if
all the lines must be read at one." },
+ "useMaps": { "index": 26, "kind": "attribute", "displayName": "Use Maps",
"group": "common", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the unmarshalling should produce
maps (HashMap) for the lines values instead of lists. It requires to have
header (either defined or collected)." },
+ "useOrderedMaps": { "index": 27, "kind": "attribute", "displayName": "Use
Ordered Maps", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether the
unmarshalling should produce ordered maps (LinkedHashMap) for the lines values
instead of lists. It requires to have header (either defined or collected)." },
+ "recordConverterRef": { "index": 28, "kind": "attribute", "displayName":
"Record Converter Ref", "group": "advanced", "label": "advanced", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "Refers to a custom
CsvRecordConverter to lookup from the registry to use." },
+ "captureHeaderRecord": { "index": 29, "kind": "attribute", "displayName":
"Capture Header Record", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether the unmarshalling should capture the header record and store it in the
message header." }
}
}
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
index 8ede88e3725f..59ab76adaf69 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
@@ -8063,6 +8063,17 @@ Whether to disable headers. Default value: false
<xs:documentation xml:lang="en">
<![CDATA[
To configure the CSV headers. Multiple headers can be separated by comma.
+]]>
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ <xs:attribute name="headerFromMapKeys" type="xs:string">
+ <xs:annotation>
+ <xs:documentation xml:lang="en">
+<![CDATA[
+When marshalling a Map, or a List of Maps, and no header is configured,
whether to write a header line with the keys of
+the first Map. The keys of the first Map are then the columns of all the rows,
as with the header option: a key that
+only later rows have is not written. Default value: false
]]>
</xs:documentation>
</xs:annotation>
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd
index c753a18c3d3f..c126e10fc4f4 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd
@@ -7182,6 +7182,17 @@ Whether to disable headers. Default value: false
<xs:documentation xml:lang="en">
<![CDATA[
To configure the CSV headers. Multiple headers can be separated by comma.
+]]>
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ <xs:attribute name="headerFromMapKeys" type="xs:string">
+ <xs:annotation>
+ <xs:documentation xml:lang="en">
+<![CDATA[
+When marshalling a Map, or a List of Maps, and no header is configured,
whether to write a header line with the keys of
+the first Map. The keys of the first Map are then the columns of all the rows,
as with the header option: a key that
+only later rows have is not written. Default value: false
]]>
</xs:documentation>
</xs:annotation>
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camelYamlDsl-model.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camelYamlDsl-model.json
index ff24d0e93816..136c3d6e6c1b 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camelYamlDsl-model.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camelYamlDsl-model.json
@@ -11126,6 +11126,16 @@
"kind" : "attribute",
"index" : 8,
"group" : "common"
+ }, {
+ "name" : "headerFromMapKeys",
+ "type" : "boolean",
+ "description" : "When marshalling a Map, or a List of Maps, and no
header is configured, whether to write a header line with the keys of the first
Map. The keys of the first Map are then the columns of all the rows, as with
the header option: a key that only later rows have is not written.",
+ "title" : "Header From Map Keys",
+ "default" : "false",
+ "displayName" : "Header From Map Keys",
+ "kind" : "attribute",
+ "index" : 9,
+ "group" : "common"
}, {
"name" : "allowMissingColumnNames",
"type" : "boolean",
@@ -11134,7 +11144,7 @@
"default" : "false",
"displayName" : "Allow Missing Column Names",
"kind" : "attribute",
- "index" : 9,
+ "index" : 10,
"group" : "common"
}, {
"name" : "ignoreEmptyLines",
@@ -11144,7 +11154,7 @@
"default" : "false",
"displayName" : "Ignore Empty Lines",
"kind" : "attribute",
- "index" : 10,
+ "index" : 11,
"group" : "common"
}, {
"name" : "ignoreSurroundingSpaces",
@@ -11154,7 +11164,7 @@
"default" : "false",
"displayName" : "Ignore Surrounding Spaces",
"kind" : "attribute",
- "index" : 11,
+ "index" : 12,
"group" : "common"
}, {
"name" : "nullStringDisabled",
@@ -11164,7 +11174,7 @@
"default" : "false",
"displayName" : "Null String Disabled",
"kind" : "attribute",
- "index" : 12,
+ "index" : 13,
"group" : "advanced",
"label" : "advanced"
}, {
@@ -11174,7 +11184,7 @@
"title" : "Null String",
"displayName" : "Null String",
"kind" : "attribute",
- "index" : 13,
+ "index" : 14,
"group" : "advanced",
"label" : "advanced"
}, {
@@ -11185,7 +11195,7 @@
"default" : "false",
"displayName" : "Quote Disabled",
"kind" : "attribute",
- "index" : 14,
+ "index" : 15,
"group" : "common"
}, {
"name" : "quote",
@@ -11194,7 +11204,7 @@
"title" : "Quote",
"displayName" : "Quote",
"kind" : "attribute",
- "index" : 15,
+ "index" : 16,
"group" : "common"
}, {
"name" : "recordSeparatorDisabled",
@@ -11204,7 +11214,7 @@
"default" : "false",
"displayName" : "Record Separator Disabled",
"kind" : "attribute",
- "index" : 16,
+ "index" : 17,
"group" : "advanced",
"label" : "advanced"
}, {
@@ -11214,7 +11224,7 @@
"title" : "Record Separator",
"displayName" : "Record Separator",
"kind" : "attribute",
- "index" : 17,
+ "index" : 18,
"group" : "common"
}, {
"name" : "skipHeaderRecord",
@@ -11224,7 +11234,7 @@
"default" : "false",
"displayName" : "Skip Header Record",
"kind" : "attribute",
- "index" : 18,
+ "index" : 19,
"group" : "common"
}, {
"name" : "quoteMode",
@@ -11234,7 +11244,7 @@
"title" : "Quote Mode",
"displayName" : "Quote Mode",
"kind" : "attribute",
- "index" : 19,
+ "index" : 20,
"group" : "common"
}, {
"name" : "ignoreHeaderCase",
@@ -11244,7 +11254,7 @@
"default" : "false",
"displayName" : "Ignore Header Case",
"kind" : "attribute",
- "index" : 20,
+ "index" : 21,
"group" : "common"
}, {
"name" : "trim",
@@ -11254,7 +11264,7 @@
"default" : "false",
"displayName" : "Trim",
"kind" : "attribute",
- "index" : 21,
+ "index" : 22,
"group" : "common"
}, {
"name" : "trailingDelimiter",
@@ -11264,7 +11274,7 @@
"default" : "false",
"displayName" : "Trailing Delimiter",
"kind" : "attribute",
- "index" : 22,
+ "index" : 23,
"group" : "common"
}, {
"name" : "marshallerFactoryRef",
@@ -11273,7 +11283,7 @@
"title" : "Marshaller Factory Ref",
"displayName" : "Marshaller Factory Ref",
"kind" : "attribute",
- "index" : 23,
+ "index" : 24,
"group" : "advanced",
"label" : "advanced"
}, {
@@ -11284,7 +11294,7 @@
"default" : "false",
"displayName" : "Lazy Load",
"kind" : "attribute",
- "index" : 24,
+ "index" : 25,
"group" : "advanced",
"label" : "advanced"
}, {
@@ -11295,7 +11305,7 @@
"default" : "false",
"displayName" : "Use Maps",
"kind" : "attribute",
- "index" : 25,
+ "index" : 26,
"group" : "common"
}, {
"name" : "useOrderedMaps",
@@ -11305,7 +11315,7 @@
"default" : "false",
"displayName" : "Use Ordered Maps",
"kind" : "attribute",
- "index" : 26,
+ "index" : 27,
"group" : "common"
}, {
"name" : "recordConverterRef",
@@ -11314,7 +11324,7 @@
"title" : "Record Converter Ref",
"displayName" : "Record Converter Ref",
"kind" : "attribute",
- "index" : 27,
+ "index" : 28,
"group" : "advanced",
"label" : "advanced"
}, {
@@ -11325,7 +11335,7 @@
"default" : "false",
"displayName" : "Capture Header Record",
"kind" : "attribute",
- "index" : 28,
+ "index" : 29,
"group" : "advanced",
"label" : "advanced"
} ]
diff --git
a/components/camel-csv/src/generated/java/org/apache/camel/dataformat/csv/CsvDataFormatConfigurer.java
b/components/camel-csv/src/generated/java/org/apache/camel/dataformat/csv/CsvDataFormatConfigurer.java
index 2a69760f5f1f..42f117d95eb1 100644
---
a/components/camel-csv/src/generated/java/org/apache/camel/dataformat/csv/CsvDataFormatConfigurer.java
+++
b/components/camel-csv/src/generated/java/org/apache/camel/dataformat/csv/CsvDataFormatConfigurer.java
@@ -33,6 +33,7 @@ public class CsvDataFormatConfigurer extends
org.apache.camel.support.component.
map.put("Format", java.lang.String.class);
map.put("Header", java.lang.String.class);
map.put("HeaderDisabled", boolean.class);
+ map.put("HeaderFromMapKeys", boolean.class);
map.put("IgnoreEmptyLines", java.lang.Boolean.class);
map.put("IgnoreHeaderCase", java.lang.Boolean.class);
map.put("IgnoreSurroundingSpaces", java.lang.Boolean.class);
@@ -72,6 +73,8 @@ public class CsvDataFormatConfigurer extends
org.apache.camel.support.component.
case "header": target.setHeader(property(camelContext,
java.lang.String.class, value)); return true;
case "headerdisabled":
case "headerDisabled": target.setHeaderDisabled(property(camelContext,
boolean.class, value)); return true;
+ case "headerfrommapkeys":
+ case "headerFromMapKeys":
target.setHeaderFromMapKeys(property(camelContext, boolean.class, value));
return true;
case "ignoreemptylines":
case "ignoreEmptyLines":
target.setIgnoreEmptyLines(property(camelContext, java.lang.Boolean.class,
value)); return true;
case "ignoreheadercase":
@@ -130,6 +133,8 @@ public class CsvDataFormatConfigurer extends
org.apache.camel.support.component.
case "header": return java.lang.String.class;
case "headerdisabled":
case "headerDisabled": return boolean.class;
+ case "headerfrommapkeys":
+ case "headerFromMapKeys": return boolean.class;
case "ignoreemptylines":
case "ignoreEmptyLines": return java.lang.Boolean.class;
case "ignoreheadercase":
@@ -184,6 +189,8 @@ public class CsvDataFormatConfigurer extends
org.apache.camel.support.component.
case "header": return target.getHeader();
case "headerdisabled":
case "headerDisabled": return target.isHeaderDisabled();
+ case "headerfrommapkeys":
+ case "headerFromMapKeys": return target.isHeaderFromMapKeys();
case "ignoreemptylines":
case "ignoreEmptyLines": return target.getIgnoreEmptyLines();
case "ignoreheadercase":
diff --git
a/components/camel-csv/src/generated/resources/META-INF/org/apache/camel/dataformat/csv/csv.json
b/components/camel-csv/src/generated/resources/META-INF/org/apache/camel/dataformat/csv/csv.json
index 2b073a8fdfe2..727f0703e14d 100644
---
a/components/camel-csv/src/generated/resources/META-INF/org/apache/camel/dataformat/csv/csv.json
+++
b/components/camel-csv/src/generated/resources/META-INF/org/apache/camel/dataformat/csv/csv.json
@@ -31,25 +31,26 @@
"escape": { "index": 6, "kind": "attribute", "displayName": "Escape",
"group": "advanced", "label": "advanced", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "description": "Sets the escape character to use." },
"headerDisabled": { "index": 7, "kind": "attribute", "displayName":
"Header Disabled", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to disable
headers." },
"header": { "index": 8, "kind": "attribute", "displayName": "Header",
"group": "common", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "To configure the CSV headers. Multiple headers can be separated
by comma." },
- "allowMissingColumnNames": { "index": 9, "kind": "attribute",
"displayName": "Allow Missing Column Names", "group": "common", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to allow missing column names." },
- "ignoreEmptyLines": { "index": 10, "kind": "attribute", "displayName":
"Ignore Empty Lines", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to ignore empty
lines." },
- "ignoreSurroundingSpaces": { "index": 11, "kind": "attribute",
"displayName": "Ignore Surrounding Spaces", "group": "common", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to ignore surrounding spaces." },
- "nullStringDisabled": { "index": 12, "kind": "attribute", "displayName":
"Null String Disabled", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to disable null string handling." },
- "nullString": { "index": 13, "kind": "attribute", "displayName": "Null
String", "group": "advanced", "label": "advanced", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "description": "Sets the null string." },
- "quoteDisabled": { "index": 14, "kind": "attribute", "displayName": "Quote
Disabled", "group": "common", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether to disable quoting." },
- "quote": { "index": 15, "kind": "attribute", "displayName": "Quote",
"group": "common", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "The quote character to use. The default is double-quote
character." },
- "recordSeparatorDisabled": { "index": 16, "kind": "attribute",
"displayName": "Record Separator Disabled", "group": "advanced", "label":
"advanced", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether to disable the record
separator." },
- "recordSeparator": { "index": 17, "kind": "attribute", "displayName":
"Record Separator", "group": "common", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "description": "The record separator (aka new line) which by
default is new line characters (CRLF)." },
- "skipHeaderRecord": { "index": 18, "kind": "attribute", "displayName":
"Skip Header Record", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to skip the
header record in the output." },
- "quoteMode": { "index": 19, "kind": "attribute", "displayName": "Quote
Mode", "group": "common", "required": false, "type": "enum", "javaType":
"java.lang.String", "enum": [ "ALL", "ALL_NON_NULL", "MINIMAL", "NON_NUMERIC",
"NONE" ], "deprecated": false, "autowired": false, "secret": false,
"description": "Sets the quote mode." },
- "ignoreHeaderCase": { "index": 20, "kind": "attribute", "displayName":
"Ignore Header Case", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to ignore case
when accessing header names." },
- "trim": { "index": 21, "kind": "attribute", "displayName": "Trim",
"group": "common", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether to trim leading and trailing
blanks." },
- "trailingDelimiter": { "index": 22, "kind": "attribute", "displayName":
"Trailing Delimiter", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to add a
trailing delimiter." },
- "marshallerFactoryRef": { "index": 23, "kind": "attribute", "displayName":
"Marshaller Factory Ref", "group": "advanced", "label": "advanced", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "Sets the implementation of
the CsvMarshallerFactory interface which is able to customize
marshalling\/unmarshalling behavior." },
- "lazyLoad": { "index": 24, "kind": "attribute", "displayName": "Lazy
Load", "group": "advanced", "label": "advanced", "required": false, "type":
"boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "description": "Whether the
unmarshalling should produce an iterator that reads the lines on the fly or if
all the lines must be read at one." },
- "useMaps": { "index": 25, "kind": "attribute", "displayName": "Use Maps",
"group": "common", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the unmarshalling should produce
maps (HashMap) for the lines values instead of lists. It requires to have
header (either defined or collected)." },
- "useOrderedMaps": { "index": 26, "kind": "attribute", "displayName": "Use
Ordered Maps", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether the
unmarshalling should produce ordered maps (LinkedHashMap) for the lines values
instead of lists. It requires to have header (either defined or collected)." },
- "recordConverterRef": { "index": 27, "kind": "attribute", "displayName":
"Record Converter Ref", "group": "advanced", "label": "advanced", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "Refers to a custom
CsvRecordConverter to lookup from the registry to use." },
- "captureHeaderRecord": { "index": 28, "kind": "attribute", "displayName":
"Capture Header Record", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether the unmarshalling should capture the header record and store it in the
message header." }
+ "headerFromMapKeys": { "index": 9, "kind": "attribute", "displayName":
"Header From Map Keys", "group": "common", "required": false, "type":
"boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "description": "When marshalling
a Map, or a List of Maps, and no header is configured, whether to write a
header line with the keys of the first Map. The keys of the first Map are then
the columns of all the rows, as with [...]
+ "allowMissingColumnNames": { "index": 10, "kind": "attribute",
"displayName": "Allow Missing Column Names", "group": "common", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to allow missing column names." },
+ "ignoreEmptyLines": { "index": 11, "kind": "attribute", "displayName":
"Ignore Empty Lines", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to ignore empty
lines." },
+ "ignoreSurroundingSpaces": { "index": 12, "kind": "attribute",
"displayName": "Ignore Surrounding Spaces", "group": "common", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to ignore surrounding spaces." },
+ "nullStringDisabled": { "index": 13, "kind": "attribute", "displayName":
"Null String Disabled", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to disable null string handling." },
+ "nullString": { "index": 14, "kind": "attribute", "displayName": "Null
String", "group": "advanced", "label": "advanced", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "description": "Sets the null string." },
+ "quoteDisabled": { "index": 15, "kind": "attribute", "displayName": "Quote
Disabled", "group": "common", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether to disable quoting." },
+ "quote": { "index": 16, "kind": "attribute", "displayName": "Quote",
"group": "common", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "The quote character to use. The default is double-quote
character." },
+ "recordSeparatorDisabled": { "index": 17, "kind": "attribute",
"displayName": "Record Separator Disabled", "group": "advanced", "label":
"advanced", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether to disable the record
separator." },
+ "recordSeparator": { "index": 18, "kind": "attribute", "displayName":
"Record Separator", "group": "common", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "description": "The record separator (aka new line) which by
default is new line characters (CRLF)." },
+ "skipHeaderRecord": { "index": 19, "kind": "attribute", "displayName":
"Skip Header Record", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to skip the
header record in the output." },
+ "quoteMode": { "index": 20, "kind": "attribute", "displayName": "Quote
Mode", "group": "common", "required": false, "type": "enum", "javaType":
"java.lang.String", "enum": [ "ALL", "ALL_NON_NULL", "MINIMAL", "NON_NUMERIC",
"NONE" ], "deprecated": false, "autowired": false, "secret": false,
"description": "Sets the quote mode." },
+ "ignoreHeaderCase": { "index": 21, "kind": "attribute", "displayName":
"Ignore Header Case", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to ignore case
when accessing header names." },
+ "trim": { "index": 22, "kind": "attribute", "displayName": "Trim",
"group": "common", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether to trim leading and trailing
blanks." },
+ "trailingDelimiter": { "index": 23, "kind": "attribute", "displayName":
"Trailing Delimiter", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to add a
trailing delimiter." },
+ "marshallerFactoryRef": { "index": 24, "kind": "attribute", "displayName":
"Marshaller Factory Ref", "group": "advanced", "label": "advanced", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "Sets the implementation of
the CsvMarshallerFactory interface which is able to customize
marshalling\/unmarshalling behavior." },
+ "lazyLoad": { "index": 25, "kind": "attribute", "displayName": "Lazy
Load", "group": "advanced", "label": "advanced", "required": false, "type":
"boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "description": "Whether the
unmarshalling should produce an iterator that reads the lines on the fly or if
all the lines must be read at one." },
+ "useMaps": { "index": 26, "kind": "attribute", "displayName": "Use Maps",
"group": "common", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the unmarshalling should produce
maps (HashMap) for the lines values instead of lists. It requires to have
header (either defined or collected)." },
+ "useOrderedMaps": { "index": 27, "kind": "attribute", "displayName": "Use
Ordered Maps", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether the
unmarshalling should produce ordered maps (LinkedHashMap) for the lines values
instead of lists. It requires to have header (either defined or collected)." },
+ "recordConverterRef": { "index": 28, "kind": "attribute", "displayName":
"Record Converter Ref", "group": "advanced", "label": "advanced", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "Refers to a custom
CsvRecordConverter to lookup from the registry to use." },
+ "captureHeaderRecord": { "index": 29, "kind": "attribute", "displayName":
"Capture Header Record", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether the unmarshalling should capture the header record and store it in the
message header." }
}
}
diff --git a/components/camel-csv/src/main/docs/csv-dataformat.adoc
b/components/camel-csv/src/main/docs/csv-dataformat.adoc
index c8fe3efceb67..c286e67f6a26 100644
--- a/components/camel-csv/src/main/docs/csv-dataformat.adoc
+++ b/components/camel-csv/src/main/docs/csv-dataformat.adoc
@@ -183,7 +183,8 @@ format, you can now store the message payload as a
each row.
When `header` is set (and `headerDisabled` is false), its names are the
-columns, in that order. Otherwise, the columns are the keys of the first Map,
+columns, in that order (the names are trimmed, so `id, name` gives the
+columns `id` and `name`). Otherwise, the columns are the keys of the first Map,
followed by the keys of later Maps that the first one does not have, in the
order they first appear (the rows written before such a key appears have
fewer fields). A Map without one of these keys gets a null value in that
@@ -202,6 +203,79 @@ that each have keys of their own (such as sparse or
pivoted data) gives
about N²/2 fields for N rows; for such data, convert the rows to Lists, or
set `header` to only the columns you need.
+==== Writing a header line from the keys of the first Map
+
+*Since Camel 4.24*
+
+Set `headerFromMapKeys` to write a header line with the keys of the first
+Map when no `header` is configured, such as when turning JSON rows into CSV:
+
+[tabs]
+====
+Java::
++
+[source,java]
+----
+CsvDataFormat csv = new CsvDataFormat();
+csv.setHeaderFromMapKeys(true);
+
+from("direct:start")
+ .unmarshal().json()
+ .marshal(csv)
+ .to("file:out?fileName=rows.csv");
+----
+
+XML::
++
+[source,xml]
+----
+<route>
+ <from uri="direct:start"/>
+ <unmarshal>
+ <json/>
+ </unmarshal>
+ <marshal>
+ <csv headerFromMapKeys="true"/>
+ </marshal>
+ <to uri="file:out?fileName=rows.csv"/>
+</route>
+----
+
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: direct:start
+ steps:
+ - unmarshal:
+ json: {}
+ - marshal:
+ csv:
+ headerFromMapKeys: true
+ - to:
+ uri: file:out
+ parameters:
+ fileName: rows.csv
+----
+====
+
+The JSON `[{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}]` is then
+written as:
+
+----
+id,name
+1,Alice
+2,Bob
+----
+
+The keys of the first Map are the columns of all the rows, as if they were
+given with `header`: a row without one of these keys gets an empty field, and
+a key that only later rows have is not written. A body whose first row is not
+a Map (such as a List of Lists) gets no header line, and `skipHeaderRecord`
+leaves the header line out.
+
=== File Poller of CSV, then unmarshaling
Given a bean which can handle the incoming data...
diff --git
a/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvDataFormat.java
b/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvDataFormat.java
index 22234b8ae4a5..9d5e9efa0ced 100644
---
a/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvDataFormat.java
+++
b/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvDataFormat.java
@@ -18,6 +18,7 @@ package org.apache.camel.dataformat.csv;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.Arrays;
import java.util.StringJoiner;
import org.apache.camel.Exchange;
@@ -75,6 +76,9 @@ public class CsvDataFormat extends ServiceSupport implements
DataFormat, DataFor
private Boolean ignoreHeaderCase;
private Boolean trailingDelimiter;
+ // Marshal options
+ private boolean headerFromMapKeys;
+
// Unmarshal options
private boolean captureHeaderRecord;
private boolean lazyLoad;
@@ -170,10 +174,12 @@ public class CsvDataFormat extends ServiceSupport
implements DataFormat, DataFor
answer = answer.builder().setHeader((String[]) null).get(); //
null disables the header
} else if (header != null && !header.isBlank()) {
// a blank header is no header, not one column named ""
+ // the names are trimmed, so "id, name" gives the columns id and
name, not " name"
if (header.indexOf(',') != -1) {
- answer = answer.builder().setHeader(header.split(",")).get();
+ answer =
answer.builder().setHeader(Arrays.stream(header.split(",")).map(String::trim).toArray(String[]::new))
+ .get();
} else {
- answer = answer.builder().setHeader(header).get();
+ answer = answer.builder().setHeader(header.trim()).get();
}
}
@@ -396,7 +402,7 @@ public class CsvDataFormat extends ServiceSupport
implements DataFormat, DataFor
}
/**
- * Gets the header. Multiple values can be separated by comma.
+ * Gets the header. Multiple values can be separated by comma, and the
names are trimmed.
*
* If {@code null}, empty or blank, then the header of the format is used.
*
@@ -407,7 +413,7 @@ public class CsvDataFormat extends ServiceSupport
implements DataFormat, DataFor
}
/**
- * Sets the header. Multiple values can be separated by comma.
+ * Sets the header. Multiple values can be separated by comma, and the
names are trimmed.
*
* If {@code null}, empty or blank, then the header of the format is used.
*
@@ -660,6 +666,29 @@ public class CsvDataFormat extends ServiceSupport
implements DataFormat, DataFor
return this;
}
+ /**
+ * Whether marshalling a Map, or a List of Maps, without a configured
header writes a header line with the keys of
+ * the first Map.
+ *
+ * @return {@code true} to write the header line from the keys of the
first Map
+ */
+ public boolean isHeaderFromMapKeys() {
+ return headerFromMapKeys;
+ }
+
+ /**
+ * When marshalling a Map, or a List of Maps, and no header is configured,
whether to write a header line with the
+ * keys of the first Map. The keys of the first Map are then the columns
of all the rows, as with the header option:
+ * a key that only later rows have is not written.
+ *
+ * @param headerFromMapKeys {@code true} to write the header line from
the keys of the first Map
+ * @return Current {@code CsvDataFormat}, fluent API
+ */
+ public CsvDataFormat setHeaderFromMapKeys(boolean headerFromMapKeys) {
+ this.headerFromMapKeys = headerFromMapKeys;
+ return this;
+ }
+
/**
* Indicates whether the unmarshalling should capture the header record.
*
diff --git
a/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvMarshaller.java
b/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvMarshaller.java
index 13079072c991..72ebcd06cc65 100644
---
a/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvMarshaller.java
+++
b/components/camel-csv/src/main/java/org/apache/camel/dataformat/csv/CsvMarshaller.java
@@ -46,6 +46,16 @@ public abstract class CsvMarshaller {
this.format = format;
}
+ /**
+ * Gets the CSV format of this marshaller.
+ *
+ * @return the CSV format
+ * @since 4.24
+ */
+ protected CSVFormat getFormat() {
+ return format;
+ }
+
/**
* Creates a new instance.
*
@@ -66,6 +76,9 @@ public abstract class CsvMarshaller {
if (headers != null && headers.length != 0) {
return new FixedColumnsMarshaller(format, headers);
}
+ if (dataFormat.isHeaderFromMapKeys() && !format.getSkipHeaderRecord())
{
+ return new MapKeysHeaderMarshaller(format);
+ }
return new DynamicColumnsMarshaller(format);
}
@@ -213,5 +226,89 @@ public abstract class CsvMarshaller {
return createMapRecordValues().apply(map);
}
}
+
+ /**
+ * This marshaller writes a header line with the keys of the first map
row, and these keys are the columns of all
+ * the rows, as with a configured header. A body whose first row is not a
map, or is an empty map, is written as by
+ * the marshaller without a header.
+ */
+ private static final class MapKeysHeaderMarshaller extends CsvMarshaller {
+
+ private MapKeysHeaderMarshaller(CSVFormat format) {
+ super(format);
+ }
+
+ @Override
+ public void marshal(Exchange exchange, Object object, OutputStream
outputStream)
+ throws NoTypeConversionAvailableException, IOException {
+ Object body = object;
+ Object first = object;
+ if (!(object instanceof Map)) {
+ // take the first row, and put it back in front of the others
(the body can be an iterator)
+ Iterator<?> it = ObjectHelper.createIterator(object);
+ first = it.hasNext() ? it.next() : null;
+ body = first != null ? prepend(first, it) : object;
+ }
+ Map<?, ?> map = first != null
+ ?
exchange.getContext().getTypeConverter().tryConvertTo(Map.class, exchange,
first) : null;
+ if (map == null || map.isEmpty()) {
+ new DynamicColumnsMarshaller(getFormat()).marshal(exchange,
body, outputStream);
+ return;
+ }
+ List<Object> columns = new ArrayList<>(map.keySet());
+ String[] header =
columns.stream().map(String::valueOf).toArray(String[]::new);
+ // the printer writes the header line of the format first
+ new
KeyColumnsMarshaller(getFormat().builder().setHeader(header).get(), columns)
+ .marshal(exchange, body, outputStream);
+ }
+
+ private static Iterator<Object> prepend(Object first, Iterator<?>
rest) {
+ return new Iterator<>() {
+ private boolean firstTaken;
+
+ @Override
+ public boolean hasNext() {
+ return !firstTaken || rest.hasNext();
+ }
+
+ @Override
+ public Object next() {
+ if (!firstTaken) {
+ firstTaken = true;
+ return first;
+ }
+ return rest.next();
+ }
+ };
+ }
+
+ @Override
+ protected Iterable<?> getMapRecordValues(Map<?, ?> map) {
+ // never called: marshal hands every body to another marshaller,
the method is only here because it is
+ // abstract in the parent
+ throw new UnsupportedOperationException("The map rows are written
by the marshaller that marshal delegates to");
+ }
+ }
+
+ /**
+ * This marshaller has the keys of a map as its fixed columns, which can
be other objects than strings.
+ */
+ private static final class KeyColumnsMarshaller extends CsvMarshaller {
+ private final List<Object> columns;
+
+ private KeyColumnsMarshaller(CSVFormat format, List<Object> columns) {
+ super(format);
+ this.columns = columns;
+ }
+
+ @Override
+ protected Iterable<?> getMapRecordValues(Map<?, ?> map) {
+ List<Object> result = new ArrayList<>(columns.size());
+ for (Object column : columns) {
+ result.add(DynamicColumnsMarshaller.valueOf(map, column));
+ }
+ return result;
+ }
+ }
//endregion
}
diff --git
a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvHeaderNamesTrimTest.java
b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvHeaderNamesTrimTest.java
new file mode 100644
index 000000000000..8c5d2d755267
--- /dev/null
+++
b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvHeaderNamesTrimTest.java
@@ -0,0 +1,97 @@
+/*
+ * 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.
+ */
+package org.apache.camel.dataformat.csv;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * The names of the header option are trimmed (CAMEL-27371): "id, name" gives
the columns id and name, not " name".
+ */
+class CsvHeaderNamesTrimTest extends CamelTestSupport {
+ @EndpointInject("mock:output")
+ MockEndpoint output;
+
+ @Test
+ void marshalFindsTheKeysOfTheTrimmedNames() throws Exception {
+ Map<String, Object> row = new LinkedHashMap<>();
+ row.put("id", "1");
+ row.put("name", "Alice");
+
+ assertEquals("id,name\r\n1,Alice\r\n", send("direct:marshal",
List.of(row), String.class));
+ }
+
+ @Test
+ void marshalOnTheUriFindsTheKeysOfTheTrimmedNames() throws Exception {
+ Map<String, Object> row = new LinkedHashMap<>();
+ row.put("id", "1");
+ row.put("name", "Alice");
+
+ assertEquals("id,name\r\n1,Alice\r\n", send("direct:marshalUri",
List.of(row), String.class));
+ }
+
+ @Test
+ void unmarshalGivesMapsWithTheTrimmedNames() throws Exception {
+ assertEquals(List.of(Map.of("id", "1", "name", "Alice")),
send("direct:unmarshal", "1,Alice\r\n", List.class));
+ }
+
+ @Test
+ void singleNameIsTrimmed() throws Exception {
+ assertEquals(List.of(Map.of("id", "1")),
send("direct:unmarshalSingle", "1\r\n", List.class));
+ }
+
+ private <T> T send(String uri, Object body, Class<T> type) throws
Exception {
+ output.reset();
+ output.expectedMessageCount(1);
+ template.sendBody(uri, body);
+ output.assertIsSatisfied();
+ return output.getExchanges().get(0).getIn().getBody(type);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:marshal")
+ .marshal(new CsvDataFormat().setHeader("id, name"))
+ .to("mock:output");
+
+ from("direct:marshalUri")
+ .to("dataformat:csv:marshal?header=id, name ")
+ .to("mock:output");
+
+ from("direct:unmarshal")
+ .unmarshal(new CsvDataFormat().setHeader(" id ,
name").setUseMaps(true))
+ .to("mock:output");
+
+ from("direct:unmarshalSingle")
+ .unmarshal(new CsvDataFormat().setHeader(" id
").setUseMaps(true))
+ .to("mock:output");
+ }
+ };
+ }
+}
diff --git
a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvMarshalHeaderFromMapKeysTest.java
b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvMarshalHeaderFromMapKeysTest.java
new file mode 100644
index 000000000000..598f3fa684b3
--- /dev/null
+++
b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvMarshalHeaderFromMapKeysTest.java
@@ -0,0 +1,153 @@
+/*
+ * 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.
+ */
+package org.apache.camel.dataformat.csv;
+
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * With headerFromMapKeys, marshalling a Map or a List of Maps without a
configured header writes a header line with the
+ * keys of the first Map (CAMEL-27371), such as for JSON rows turned into CSV.
+ */
+class CsvMarshalHeaderFromMapKeysTest extends CamelTestSupport {
+ @EndpointInject("mock:output")
+ MockEndpoint output;
+
+ @Test
+ void listOfMapsGetsAHeaderLineFromTheKeysOfTheFirstMap() throws Exception {
+ assertEquals("id,name\r\n1,Alice\r\n2,Bob\r\n",
+ marshal("direct:keys", List.of(row("id", "1", "name",
"Alice"), row("name", "Bob", "id", "2"))));
+ }
+
+ @Test
+ void keysOfTheFirstMapAreTheColumns() throws Exception {
+ // a missing key gives an empty field, a key that only a later row has
is not written, as with the header option
+ assertEquals("id,name\r\n1,Alice\r\n2,\r\n3,Carol\r\n",
+ marshal("direct:keys", List.of(row("id", "1", "name",
"Alice"), row("id", "2", "city", "Rome"),
+ row("city", "Bergen", "name", "Carol", "id", "3"))));
+ }
+
+ @Test
+ void singleMapGetsAHeaderLine() throws Exception {
+ assertEquals("id,name\r\n1,Alice\r\n", marshal("direct:keys",
row("id", "1", "name", "Alice")));
+ }
+
+ @Test
+ void iteratorOfMapsGetsAHeaderLine() throws Exception {
+ Iterator<Map<String, Object>> rows = List.of(row("id", "1"), row("id",
"2")).iterator();
+ assertEquals("id\r\n1\r\n2\r\n", marshal("direct:keys", rows));
+ }
+
+ @Test
+ void keysThatAreNotStrings() throws Exception {
+ Map<Object, Object> first = new LinkedHashMap<>();
+ first.put(1, "a");
+ first.put(2, "b");
+ Map<Object, Object> second = new LinkedHashMap<>();
+ second.put(2, "d");
+ second.put(1, "c");
+ assertEquals("1,2\r\na,b\r\nc,d\r\n", marshal("direct:keys",
List.of(first, second)));
+ }
+
+ @Test
+ void listRowsGetNoHeaderLine() throws Exception {
+ assertEquals("1,Alice\r\n2,Bob\r\n", marshal("direct:keys",
List.of(List.of("1", "Alice"), List.of("2", "Bob"))));
+ }
+
+ @Test
+ void configuredHeaderWins() throws Exception {
+ assertEquals("name\r\nAlice\r\n", marshal("direct:keysAndHeader",
List.of(row("id", "1", "name", "Alice"))));
+ }
+
+ @Test
+ void skipHeaderRecordWritesNoHeaderLine() throws Exception {
+ assertEquals("1,Alice\r\n", marshal("direct:keysSkipHeader",
List.of(row("id", "1", "name", "Alice"))));
+ }
+
+ @Test
+ void withoutTheOptionNoHeaderLine() throws Exception {
+ assertEquals("1,Alice\r\n", marshal("direct:default",
List.of(row("id", "1", "name", "Alice"))));
+ }
+
+ @Test
+ void optionOfTheModel() throws Exception {
+ assertEquals("id,name\r\n1,Alice\r\n", marshal("direct:model",
List.of(row("id", "1", "name", "Alice"))));
+ }
+
+ @Test
+ void optionOnTheUri() throws Exception {
+ assertEquals("id,name\r\n1,Alice\r\n", marshal("direct:uri",
List.of(row("id", "1", "name", "Alice"))));
+ }
+
+ private String marshal(String uri, Object body) throws Exception {
+ output.reset();
+ output.expectedMessageCount(1);
+ template.sendBody(uri, body);
+ output.assertIsSatisfied();
+ return output.getExchanges().get(0).getIn().getBody(String.class);
+ }
+
+ private static Map<String, Object> row(String... keyValues) {
+ Map<String, Object> map = new LinkedHashMap<>();
+ for (int i = 0; i < keyValues.length; i += 2) {
+ map.put(keyValues[i], keyValues[i + 1]);
+ }
+ return map;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:keys")
+ .marshal(new
CsvDataFormat().setHeaderFromMapKeys(true))
+ .to("mock:output");
+
+ from("direct:keysAndHeader")
+ .marshal(new
CsvDataFormat().setHeaderFromMapKeys(true).setHeader("name"))
+ .to("mock:output");
+
+ from("direct:keysSkipHeader")
+ .marshal(new
CsvDataFormat().setHeaderFromMapKeys(true).setSkipHeaderRecord(true))
+ .to("mock:output");
+
+ from("direct:default")
+ .marshal(new CsvDataFormat())
+ .to("mock:output");
+
+ from("direct:model")
+
.marshal(dataFormat().csv().headerFromMapKeys(true).end())
+ .to("mock:output");
+
+ from("direct:uri")
+ .to("dataformat:csv:marshal?headerFromMapKeys=true")
+ .to("mock:output");
+ }
+ };
+ }
+}
diff --git
a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalNullBodyTest.java
b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalNullBodyTest.java
new file mode 100644
index 000000000000..cfeb63b2f65c
--- /dev/null
+++
b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalNullBodyTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.
+ */
+package org.apache.camel.dataformat.csv;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.NoTypeConversionAvailableException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Unmarshalling a null body says there is nothing to unmarshal, with a hint
that reads a CSV file, not a JSON one
+ * (CAMEL-27371).
+ */
+class CsvUnmarshalNullBodyTest extends CamelTestSupport {
+
+ @Test
+ void nullBodyFailsWithACsvHint() {
+ CamelExecutionException e
+ = assertThrows(CamelExecutionException.class, () ->
template.sendBody("direct:unmarshal", null));
+ NoTypeConversionAvailableException cause =
assertInstanceOf(NoTypeConversionAvailableException.class, e.getCause());
+ String message = cause.getMessage();
+ assertTrue(message.startsWith("Cannot unmarshal using csv: the body is
null, so there is nothing to unmarshal"),
+ message);
+ assertTrue(message.contains("resource:file:data.csv"), message);
+ assertFalse(message.contains("json"), message);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:unmarshal")
+ .unmarshal(new CsvDataFormat())
+ .to("mock:output");
+ }
+ };
+ }
+}
diff --git
a/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/csv.json
b/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/csv.json
index 557f4f550279..e0c608d32d77 100644
---
a/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/csv.json
+++
b/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/csv.json
@@ -22,25 +22,26 @@
"escape": { "index": 6, "kind": "attribute", "displayName": "Escape",
"group": "advanced", "label": "advanced", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "description": "Sets the escape character to use." },
"headerDisabled": { "index": 7, "kind": "attribute", "displayName":
"Header Disabled", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to disable
headers." },
"header": { "index": 8, "kind": "attribute", "displayName": "Header",
"group": "common", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "To configure the CSV headers. Multiple headers can be separated
by comma." },
- "allowMissingColumnNames": { "index": 9, "kind": "attribute",
"displayName": "Allow Missing Column Names", "group": "common", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to allow missing column names." },
- "ignoreEmptyLines": { "index": 10, "kind": "attribute", "displayName":
"Ignore Empty Lines", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to ignore empty
lines." },
- "ignoreSurroundingSpaces": { "index": 11, "kind": "attribute",
"displayName": "Ignore Surrounding Spaces", "group": "common", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to ignore surrounding spaces." },
- "nullStringDisabled": { "index": 12, "kind": "attribute", "displayName":
"Null String Disabled", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to disable null string handling." },
- "nullString": { "index": 13, "kind": "attribute", "displayName": "Null
String", "group": "advanced", "label": "advanced", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "description": "Sets the null string." },
- "quoteDisabled": { "index": 14, "kind": "attribute", "displayName": "Quote
Disabled", "group": "common", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether to disable quoting." },
- "quote": { "index": 15, "kind": "attribute", "displayName": "Quote",
"group": "common", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "The quote character to use. The default is double-quote
character." },
- "recordSeparatorDisabled": { "index": 16, "kind": "attribute",
"displayName": "Record Separator Disabled", "group": "advanced", "label":
"advanced", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether to disable the record
separator." },
- "recordSeparator": { "index": 17, "kind": "attribute", "displayName":
"Record Separator", "group": "common", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "description": "The record separator (aka new line) which by
default is new line characters (CRLF)." },
- "skipHeaderRecord": { "index": 18, "kind": "attribute", "displayName":
"Skip Header Record", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to skip the
header record in the output." },
- "quoteMode": { "index": 19, "kind": "attribute", "displayName": "Quote
Mode", "group": "common", "required": false, "type": "enum", "javaType":
"java.lang.String", "enum": [ "ALL", "ALL_NON_NULL", "MINIMAL", "NON_NUMERIC",
"NONE" ], "deprecated": false, "autowired": false, "secret": false,
"description": "Sets the quote mode." },
- "ignoreHeaderCase": { "index": 20, "kind": "attribute", "displayName":
"Ignore Header Case", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to ignore case
when accessing header names." },
- "trim": { "index": 21, "kind": "attribute", "displayName": "Trim",
"group": "common", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether to trim leading and trailing
blanks." },
- "trailingDelimiter": { "index": 22, "kind": "attribute", "displayName":
"Trailing Delimiter", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to add a
trailing delimiter." },
- "marshallerFactoryRef": { "index": 23, "kind": "attribute", "displayName":
"Marshaller Factory Ref", "group": "advanced", "label": "advanced", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "Sets the implementation of
the CsvMarshallerFactory interface which is able to customize
marshalling\/unmarshalling behavior." },
- "lazyLoad": { "index": 24, "kind": "attribute", "displayName": "Lazy
Load", "group": "advanced", "label": "advanced", "required": false, "type":
"boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "description": "Whether the
unmarshalling should produce an iterator that reads the lines on the fly or if
all the lines must be read at one." },
- "useMaps": { "index": 25, "kind": "attribute", "displayName": "Use Maps",
"group": "common", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the unmarshalling should produce
maps (HashMap) for the lines values instead of lists. It requires to have
header (either defined or collected)." },
- "useOrderedMaps": { "index": 26, "kind": "attribute", "displayName": "Use
Ordered Maps", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether the
unmarshalling should produce ordered maps (LinkedHashMap) for the lines values
instead of lists. It requires to have header (either defined or collected)." },
- "recordConverterRef": { "index": 27, "kind": "attribute", "displayName":
"Record Converter Ref", "group": "advanced", "label": "advanced", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "Refers to a custom
CsvRecordConverter to lookup from the registry to use." },
- "captureHeaderRecord": { "index": 28, "kind": "attribute", "displayName":
"Capture Header Record", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether the unmarshalling should capture the header record and store it in the
message header." }
+ "headerFromMapKeys": { "index": 9, "kind": "attribute", "displayName":
"Header From Map Keys", "group": "common", "required": false, "type":
"boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "description": "When marshalling
a Map, or a List of Maps, and no header is configured, whether to write a
header line with the keys of the first Map. The keys of the first Map are then
the columns of all the rows, as with [...]
+ "allowMissingColumnNames": { "index": 10, "kind": "attribute",
"displayName": "Allow Missing Column Names", "group": "common", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to allow missing column names." },
+ "ignoreEmptyLines": { "index": 11, "kind": "attribute", "displayName":
"Ignore Empty Lines", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to ignore empty
lines." },
+ "ignoreSurroundingSpaces": { "index": 12, "kind": "attribute",
"displayName": "Ignore Surrounding Spaces", "group": "common", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to ignore surrounding spaces." },
+ "nullStringDisabled": { "index": 13, "kind": "attribute", "displayName":
"Null String Disabled", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to disable null string handling." },
+ "nullString": { "index": 14, "kind": "attribute", "displayName": "Null
String", "group": "advanced", "label": "advanced", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "description": "Sets the null string." },
+ "quoteDisabled": { "index": 15, "kind": "attribute", "displayName": "Quote
Disabled", "group": "common", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether to disable quoting." },
+ "quote": { "index": 16, "kind": "attribute", "displayName": "Quote",
"group": "common", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "The quote character to use. The default is double-quote
character." },
+ "recordSeparatorDisabled": { "index": 17, "kind": "attribute",
"displayName": "Record Separator Disabled", "group": "advanced", "label":
"advanced", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether to disable the record
separator." },
+ "recordSeparator": { "index": 18, "kind": "attribute", "displayName":
"Record Separator", "group": "common", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": false, "description": "The record separator (aka new line) which by
default is new line characters (CRLF)." },
+ "skipHeaderRecord": { "index": 19, "kind": "attribute", "displayName":
"Skip Header Record", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to skip the
header record in the output." },
+ "quoteMode": { "index": 20, "kind": "attribute", "displayName": "Quote
Mode", "group": "common", "required": false, "type": "enum", "javaType":
"java.lang.String", "enum": [ "ALL", "ALL_NON_NULL", "MINIMAL", "NON_NUMERIC",
"NONE" ], "deprecated": false, "autowired": false, "secret": false,
"description": "Sets the quote mode." },
+ "ignoreHeaderCase": { "index": 21, "kind": "attribute", "displayName":
"Ignore Header Case", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to ignore case
when accessing header names." },
+ "trim": { "index": 22, "kind": "attribute", "displayName": "Trim",
"group": "common", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether to trim leading and trailing
blanks." },
+ "trailingDelimiter": { "index": 23, "kind": "attribute", "displayName":
"Trailing Delimiter", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether to add a
trailing delimiter." },
+ "marshallerFactoryRef": { "index": 24, "kind": "attribute", "displayName":
"Marshaller Factory Ref", "group": "advanced", "label": "advanced", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "Sets the implementation of
the CsvMarshallerFactory interface which is able to customize
marshalling\/unmarshalling behavior." },
+ "lazyLoad": { "index": 25, "kind": "attribute", "displayName": "Lazy
Load", "group": "advanced", "label": "advanced", "required": false, "type":
"boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "description": "Whether the
unmarshalling should produce an iterator that reads the lines on the fly or if
all the lines must be read at one." },
+ "useMaps": { "index": 26, "kind": "attribute", "displayName": "Use Maps",
"group": "common", "required": false, "type": "boolean", "javaType":
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the unmarshalling should produce
maps (HashMap) for the lines values instead of lists. It requires to have
header (either defined or collected)." },
+ "useOrderedMaps": { "index": 27, "kind": "attribute", "displayName": "Use
Ordered Maps", "group": "common", "required": false, "type": "boolean",
"javaType": "java.lang.Boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Whether the
unmarshalling should produce ordered maps (LinkedHashMap) for the lines values
instead of lists. It requires to have header (either defined or collected)." },
+ "recordConverterRef": { "index": 28, "kind": "attribute", "displayName":
"Record Converter Ref", "group": "advanced", "label": "advanced", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "Refers to a custom
CsvRecordConverter to lookup from the registry to use." },
+ "captureHeaderRecord": { "index": 29, "kind": "attribute", "displayName":
"Capture Header Record", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether the unmarshalling should capture the header record and store it in the
message header." }
}
}
diff --git
a/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/CsvDataFormat.java
b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/CsvDataFormat.java
index f82309241b41..5182defc1ee4 100644
---
a/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/CsvDataFormat.java
+++
b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/CsvDataFormat.java
@@ -65,6 +65,13 @@ public class CsvDataFormat extends DataFormatDefinition {
@Metadata(description = "To configure the CSV headers. Multiple headers
can be separated by comma.")
private String header;
@XmlAttribute
+ @Metadata(javaType = "java.lang.Boolean",
+ description = "When marshalling a Map, or a List of Maps, and no
header is configured, whether to write a"
+ + " header line with the keys of the first Map.
The keys of the first Map are then the columns"
+ + " of all the rows, as with the header option: a
key that only later rows have is not"
+ + " written.")
+ private String headerFromMapKeys;
+ @XmlAttribute
@Metadata(javaType = "java.lang.Boolean", description = "Whether to allow
missing column names.")
private String allowMissingColumnNames;
@XmlAttribute
@@ -153,6 +160,7 @@ public class CsvDataFormat extends DataFormatDefinition {
this.escape = source.escape;
this.headerDisabled = source.headerDisabled;
this.header = source.header;
+ this.headerFromMapKeys = source.headerFromMapKeys;
this.allowMissingColumnNames = source.allowMissingColumnNames;
this.ignoreEmptyLines = source.ignoreEmptyLines;
this.ignoreSurroundingSpaces = source.ignoreSurroundingSpaces;
@@ -195,6 +203,7 @@ public class CsvDataFormat extends DataFormatDefinition {
this.escape = builder.escape;
this.headerDisabled = builder.headerDisabled;
this.header = builder.header;
+ this.headerFromMapKeys = builder.headerFromMapKeys;
this.allowMissingColumnNames = builder.allowMissingColumnNames;
this.ignoreEmptyLines = builder.ignoreEmptyLines;
this.ignoreSurroundingSpaces = builder.ignoreSurroundingSpaces;
@@ -294,6 +303,14 @@ public class CsvDataFormat extends DataFormatDefinition {
this.header = header;
}
+ public String getHeaderFromMapKeys() {
+ return headerFromMapKeys;
+ }
+
+ public void setHeaderFromMapKeys(String headerFromMapKeys) {
+ this.headerFromMapKeys = headerFromMapKeys;
+ }
+
public String getAllowMissingColumnNames() {
return allowMissingColumnNames;
}
@@ -459,6 +476,7 @@ public class CsvDataFormat extends DataFormatDefinition {
private String escape;
private String headerDisabled;
private String header;
+ private String headerFromMapKeys;
private String allowMissingColumnNames;
private String ignoreEmptyLines;
private String ignoreSurroundingSpaces;
@@ -575,6 +593,26 @@ public class CsvDataFormat extends DataFormatDefinition {
return this;
}
+ /**
+ * When marshalling a Map, or a List of Maps, and no header is
configured, whether to write a header line with
+ * the keys of the first Map. The keys of the first Map are then the
columns of all the rows, as with the header
+ * option: a key that only later rows have is not written.
+ */
+ public Builder headerFromMapKeys(String headerFromMapKeys) {
+ this.headerFromMapKeys = headerFromMapKeys;
+ return this;
+ }
+
+ /**
+ * When marshalling a Map, or a List of Maps, and no header is
configured, whether to write a header line with
+ * the keys of the first Map. The keys of the first Map are then the
columns of all the rows, as with the header
+ * option: a key that only later rows have is not written.
+ */
+ public Builder headerFromMapKeys(boolean headerFromMapKeys) {
+ this.headerFromMapKeys = Boolean.toString(headerFromMapKeys);
+ return this;
+ }
+
/**
* Whether to allow missing column names.
*/
diff --git
a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/CsvDataFormatReifier.java
b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/CsvDataFormatReifier.java
index 477a6e70aae2..e942c6e3f60b 100644
---
a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/CsvDataFormatReifier.java
+++
b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/CsvDataFormatReifier.java
@@ -38,6 +38,7 @@ public class CsvDataFormatReifier extends
DataFormatReifier<CsvDataFormat> {
properties.put("escape", definition.getEscape());
properties.put("headerDisabled", definition.getHeaderDisabled());
properties.put("header", definition.getHeader());
+ properties.put("headerFromMapKeys", definition.getHeaderFromMapKeys());
properties.put("allowMissingColumnNames",
definition.getAllowMissingColumnNames());
properties.put("ignoreEmptyLines", definition.getIgnoreEmptyLines());
properties.put("ignoreSurroundingSpaces",
definition.getIgnoreSurroundingSpaces());
diff --git
a/core/camel-core/src/test/java/org/apache/camel/support/BodyFactsTest.java
b/core/camel-core/src/test/java/org/apache/camel/support/BodyFactsTest.java
index 1709410e1ee5..426d5260c8ac 100644
--- a/core/camel-core/src/test/java/org/apache/camel/support/BodyFactsTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/support/BodyFactsTest.java
@@ -208,6 +208,22 @@ public class BodyFactsTest extends ContextTestSupport {
assertNull(BodyFacts.hint(exchange("x"), Need.A_BODY));
}
+ @Test
+ public void testABodyHintNamesAFileOfTheDataFormat() {
+ // the unmarshal of a data format names a file of its data, not a JSON
file for a CSV error (CAMEL-27371)
+ assertTrue(BodyFacts.hint(exchange(null), Need.A_BODY,
"csv").contains("resource:file:data.csv for a known file"));
+ assertTrue(BodyFacts.hint(exchange(null), Need.A_BODY,
null).contains("resource:file:data.json for a known file"));
+ assertEquals("data.csv", BodyFacts.dataFile("csv"));
+ assertEquals("data.csv", BodyFacts.dataFile("univocityCsv"));
+ assertEquals("data.tsv", BodyFacts.dataFile("univocityTsv"));
+ assertEquals("data.xml", BodyFacts.dataFile("jacksonXml"));
+ assertEquals("data.xml", BodyFacts.dataFile("jaxb"));
+ assertEquals("data.yaml", BodyFacts.dataFile("yaml"));
+ assertEquals("data.json", BodyFacts.dataFile("json"));
+ assertEquals("data.json", BodyFacts.dataFile("MyDataFormat"));
+ assertEquals("data.json", BodyFacts.dataFile(null));
+ }
+
@Test
public void testTheKindOfABody() {
assertEquals(Kind.NULL, BodyFacts.kindOf(null));
diff --git
a/core/camel-java-io/src/generated/java/org/apache/camel/java/out/JavaDslModelWriter.java
b/core/camel-java-io/src/generated/java/org/apache/camel/java/out/JavaDslModelWriter.java
index 7f060c1d3e3f..6378cc90f1d1 100644
---
a/core/camel-java-io/src/generated/java/org/apache/camel/java/out/JavaDslModelWriter.java
+++
b/core/camel-java-io/src/generated/java/org/apache/camel/java/out/JavaDslModelWriter.java
@@ -2967,6 +2967,7 @@ public class JavaDslModelWriter extends
JavaDslModelWriterSupport {
doWriteAttribute(sb, "escape", def.getEscape(), null);
doWriteAttribute(sb, "headerDisabled", def.getHeaderDisabled(), null);
doWriteAttribute(sb, "header", def.getHeader(), null);
+ doWriteAttribute(sb, "headerFromMapKeys", def.getHeaderFromMapKeys(),
null);
doWriteAttribute(sb, "allowMissingColumnNames",
def.getAllowMissingColumnNames(), null);
doWriteAttribute(sb, "ignoreEmptyLines", def.getIgnoreEmptyLines(),
null);
doWriteAttribute(sb, "ignoreSurroundingSpaces",
def.getIgnoreSurroundingSpaces(), null);
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/BodyFacts.java
b/core/camel-support/src/main/java/org/apache/camel/support/BodyFacts.java
index c978930ca3e6..bac9bd7536c8 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/BodyFacts.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/BodyFacts.java
@@ -156,6 +156,9 @@ public final class BodyFacts {
A_BODY
}
+ /** The file in the hint to read the data first, when the data format is
not known. */
+ private static final String DATA_FILE = "data.json";
+
/** At most this many keys of a Map are listed. */
private static final int MAX_KEYS = 20;
@@ -183,14 +186,15 @@ public final class BodyFacts {
/**
* What to write so that the failing step gets the body it needs; null
when the body is not why it failed. For
* {@link Need#BYTES}, target is what the step writes: its Content-Type,
or the name of the file, which names the
- * data format to marshal to; it is not used for the other needs.
+ * data format to marshal to. For {@link Need#A_BODY}, target is the name
of the data format that reads the body
+ * (csv), so the file in the hint is one of its data (data.csv); it is not
used for {@link Need#DATA}.
*/
public static String hint(Exchange exchange, Need need, String target) {
Object body = exchange.getMessage().getBody();
String answer = switch (need) {
case DATA -> dataHint(exchange, body);
case BYTES -> bytesHint(body, target);
- case A_BODY -> isEmpty(body) ? readTheDataFirst(exchange, body) :
null;
+ case A_BODY -> isEmpty(body) ? readTheDataFirst(exchange, body,
dataFile(target)) : null;
};
return answer != null ? answer + otherBodies(exchange, body) : null;
}
@@ -216,9 +220,30 @@ public final class BodyFacts {
return null;
}
+ /**
+ * A file of the data that a data format reads, for the hint: data.csv for
csv; data.json when the data format is
+ * not known, or reads json.
+ */
+ static String dataFile(String dataFormat) {
+ if (dataFormat == null) {
+ return DATA_FILE;
+ }
+ String name = dataFormat.toLowerCase(Locale.ROOT);
+ if (name.contains("csv")) {
+ return "data.csv";
+ } else if (name.contains("tsv")) {
+ return "data.tsv";
+ } else if (name.contains("xml") || name.equals("jaxb")) {
+ return "data.xml";
+ } else if (name.contains("yaml")) {
+ return "data.yaml";
+ }
+ return DATA_FILE;
+ }
+
private static String dataHint(Exchange exchange, Object body) {
if (isEmpty(body)) {
- return readTheDataFirst(exchange, body);
+ return readTheDataFirst(exchange, body, DATA_FILE);
}
if (isPayload(body)) {
String marshal = marshalledData(exchange, body);
@@ -320,13 +345,13 @@ public final class BodyFacts {
* route emptied it, as the message history says, read what is needed
before that step. r23 (http-client s1): the
* route set the body to ${null} and then read ${body[sku]}, and "read the
data first" did not fit.
*/
- private static String readTheDataFirst(Exchange exchange, Object body) {
+ private static String readTheDataFirst(Exchange exchange, Object body,
String dataFile) {
String emptiedBy = emptiedBy(exchange, body);
if (emptiedBy != null) {
return "the " + emptiedBy + " emptied it: read what is needed
before that step, for example into a variable"
+ " with setVariable, or write a fixed value as a constant
where it is used";
}
- return readTheDataFirst();
+ return readTheDataFirst(dataFile);
}
/** The setBody or transform that left the body null or empty, from the
message history; or null. */
@@ -348,8 +373,8 @@ public final class BodyFacts {
return null;
}
- private static String readTheDataFirst() {
- return "read the data first - setBody with constant:
resource:file:data.json for a known file, or poll:,"
+ private static String readTheDataFirst(String dataFile) {
+ return "read the data first - setBody with constant: resource:file:" +
dataFile + " for a known file, or poll:,"
+ " pollEnrich or a from: consumer for one that is not (a route
reached with direct: has the body of its"
+ " caller)";
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/processor/UnmarshalProcessor.java
b/core/camel-support/src/main/java/org/apache/camel/support/processor/UnmarshalProcessor.java
index 1da209be9f39..c2314f1f0e7f 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/processor/UnmarshalProcessor.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/processor/UnmarshalProcessor.java
@@ -153,7 +153,7 @@ public class UnmarshalProcessor extends
AsyncProcessorSupport
? "Cannot unmarshal using " + name + ": the variable " +
variableSend + " is null, so there is nothing to"
+ " unmarshal. Set the variable " + variableSend + " first,
or set allowNullBody=true to skip a null body."
: "Cannot unmarshal using " + name + ": " +
BodyFacts.describe(exchange)
- + ", so there is nothing to unmarshal: " +
BodyFacts.hint(exchange, BodyFacts.Need.A_BODY)
+ + ", so there is nothing to unmarshal: " +
BodyFacts.hint(exchange, BodyFacts.Need.A_BODY, name)
+ "; or set allowNullBody=true to skip a null body.";
NoTypeConversionAvailableException answer = new
NoTypeConversionAvailableException(message, null, ntc.getToType());
answer.initCause(e);
diff --git
a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java
b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java
index 4b9586c56560..c7a0a2145751 100644
---
a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java
+++
b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java
@@ -1703,6 +1703,7 @@ public class ModelParser extends BaseParser {
case "format": def.setFormat(val); yield true;
case "header": def.setHeader(val); yield true;
case "headerDisabled": def.setHeaderDisabled(val); yield true;
+ case "headerFromMapKeys": def.setHeaderFromMapKeys(val); yield
true;
case "ignoreEmptyLines": def.setIgnoreEmptyLines(val); yield
true;
case "ignoreHeaderCase": def.setIgnoreHeaderCase(val); yield
true;
case "ignoreSurroundingSpaces":
def.setIgnoreSurroundingSpaces(val); yield true;
diff --git
a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java
b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java
index 3559f6f07d43..acd920299405 100644
---
a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java
+++
b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java
@@ -2293,6 +2293,7 @@ public class ModelWriter extends BaseWriter {
doWriteAttribute("escape", def.getEscape(), null);
doWriteAttribute("headerDisabled", def.getHeaderDisabled(), null);
doWriteAttribute("header", def.getHeader(), null);
+ doWriteAttribute("headerFromMapKeys", def.getHeaderFromMapKeys(),
null);
doWriteAttribute("allowMissingColumnNames",
def.getAllowMissingColumnNames(), null);
doWriteAttribute("ignoreEmptyLines", def.getIgnoreEmptyLines(), null);
doWriteAttribute("ignoreSurroundingSpaces",
def.getIgnoreSurroundingSpaces(), null);
diff --git
a/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/YamlModelWriter.java
b/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/YamlModelWriter.java
index 93ad006f9d9f..ba297105124f 100644
---
a/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/YamlModelWriter.java
+++
b/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/YamlModelWriter.java
@@ -2293,6 +2293,7 @@ public class YamlModelWriter extends
YamlModelWriterSupport {
doWriteAttribute(jo, "escape", def.getEscape(), null);
doWriteAttribute(jo, "headerDisabled", def.getHeaderDisabled(), null);
doWriteAttribute(jo, "header", def.getHeader(), null);
+ doWriteAttribute(jo, "headerFromMapKeys", def.getHeaderFromMapKeys(),
null);
doWriteAttribute(jo, "allowMissingColumnNames",
def.getAllowMissingColumnNames(), null);
doWriteAttribute(jo, "ignoreEmptyLines", def.getIgnoreEmptyLines(),
null);
doWriteAttribute(jo, "ignoreSurroundingSpaces",
def.getIgnoreSurroundingSpaces(), null);
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index e2603b9e7b70..d85027630df6 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -5384,6 +5384,12 @@ the previous output, convert the rows to `List` before
marshalling, or set a cus
now has all the columns seen so far in the body, so rows that each have keys
of their own (sparse or pivoted data)
give about N²/2 fields for N rows, where the output was linear in the input
before.
+=== camel-csv - the names of the header option are trimmed
+
+The names of the `header` option are now trimmed, so `header=id, name` gives
the columns `id` and `name`. Before, the
+second column was named ` name`: marshalling a `Map` with the key `name` wrote
an empty field, and unmarshalling with
+`useMaps=true` gave maps with the key ` name`.
+
=== camel-cxf - message bodies of the POJO producer and of CXF_MESSAGE, and
replies that do not convert
The `cxf` producer in `POJO` mode split a body that is not a `List` or an
`Object[]` into several parameters, the way
diff --git
a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java
b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java
index b62386e3578f..1f99e5420fae 100644
---
a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java
+++
b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java
@@ -2732,6 +2732,7 @@ public final class ModelDeserializers extends
YamlDeserializerSupport {
@YamlProperty(name = "format", type =
"enum:DEFAULT,EXCEL,INFORMIX_UNLOAD,INFORMIX_UNLOAD_CSV,MONGODB_CSV,MONGODB_TSV,MYSQL,ORACLE,POSTGRESQL_CSV,POSTGRESQL_TEXT,RFC4180",
defaultValue = "DEFAULT", description = "The format to use.", displayName =
"Format"),
@YamlProperty(name = "header", type = "string",
description = "To configure the CSV headers. Multiple headers can be separated
by comma.", displayName = "Header"),
@YamlProperty(name = "headerDisabled", type = "boolean",
defaultValue = "false", description = "Whether to disable headers.",
displayName = "Header Disabled"),
+ @YamlProperty(name = "headerFromMapKeys", type =
"boolean", defaultValue = "false", description = "When marshalling a Map, or a
List of Maps, and no header is configured, whether to write a header line with
the keys of the first Map. The keys of the first Map are then the columns of
all the rows, as with the header option: a key that only later rows have is not
written.", displayName = "Header From Map Keys"),
@YamlProperty(name = "id", type = "string", description =
"The id of this node", displayName = "Id"),
@YamlProperty(name = "ignoreEmptyLines", type = "boolean",
defaultValue = "false", description = "Whether to ignore empty lines.",
displayName = "Ignore Empty Lines"),
@YamlProperty(name = "ignoreHeaderCase", type = "boolean",
defaultValue = "false", description = "Whether to ignore case when accessing
header names.", displayName = "Ignore Header Case"),
@@ -2823,6 +2824,11 @@ public final class ModelDeserializers extends
YamlDeserializerSupport {
target.setHeaderDisabled(val);
break;
}
+ case "headerFromMapKeys": {
+ String val = asText(node);
+ target.setHeaderFromMapKeys(val);
+ break;
+ }
case "id": {
String val = asText(node);
target.setId(val);
diff --git
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl-canonical.json
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl-canonical.json
index 13394bb38fe4..0a10dcf9ec0d 100644
---
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl-canonical.json
+++
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl-canonical.json
@@ -6849,6 +6849,12 @@
"description" : "Whether to disable headers.",
"default" : false
},
+ "headerFromMapKeys" : {
+ "type" : "boolean",
+ "title" : "Header From Map Keys",
+ "description" : "When marshalling a Map, or a List of Maps, and no
header is configured, whether to write a header line with the keys of the first
Map. The keys of the first Map are then the columns of all the rows, as with
the header option: a key that only later rows have is not written.",
+ "default" : false
+ },
"id" : {
"type" : "string",
"title" : "Id",
diff --git
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl-model.json
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl-model.json
index ff24d0e93816..136c3d6e6c1b 100644
---
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl-model.json
+++
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl-model.json
@@ -11126,6 +11126,16 @@
"kind" : "attribute",
"index" : 8,
"group" : "common"
+ }, {
+ "name" : "headerFromMapKeys",
+ "type" : "boolean",
+ "description" : "When marshalling a Map, or a List of Maps, and no
header is configured, whether to write a header line with the keys of the first
Map. The keys of the first Map are then the columns of all the rows, as with
the header option: a key that only later rows have is not written.",
+ "title" : "Header From Map Keys",
+ "default" : "false",
+ "displayName" : "Header From Map Keys",
+ "kind" : "attribute",
+ "index" : 9,
+ "group" : "common"
}, {
"name" : "allowMissingColumnNames",
"type" : "boolean",
@@ -11134,7 +11144,7 @@
"default" : "false",
"displayName" : "Allow Missing Column Names",
"kind" : "attribute",
- "index" : 9,
+ "index" : 10,
"group" : "common"
}, {
"name" : "ignoreEmptyLines",
@@ -11144,7 +11154,7 @@
"default" : "false",
"displayName" : "Ignore Empty Lines",
"kind" : "attribute",
- "index" : 10,
+ "index" : 11,
"group" : "common"
}, {
"name" : "ignoreSurroundingSpaces",
@@ -11154,7 +11164,7 @@
"default" : "false",
"displayName" : "Ignore Surrounding Spaces",
"kind" : "attribute",
- "index" : 11,
+ "index" : 12,
"group" : "common"
}, {
"name" : "nullStringDisabled",
@@ -11164,7 +11174,7 @@
"default" : "false",
"displayName" : "Null String Disabled",
"kind" : "attribute",
- "index" : 12,
+ "index" : 13,
"group" : "advanced",
"label" : "advanced"
}, {
@@ -11174,7 +11184,7 @@
"title" : "Null String",
"displayName" : "Null String",
"kind" : "attribute",
- "index" : 13,
+ "index" : 14,
"group" : "advanced",
"label" : "advanced"
}, {
@@ -11185,7 +11195,7 @@
"default" : "false",
"displayName" : "Quote Disabled",
"kind" : "attribute",
- "index" : 14,
+ "index" : 15,
"group" : "common"
}, {
"name" : "quote",
@@ -11194,7 +11204,7 @@
"title" : "Quote",
"displayName" : "Quote",
"kind" : "attribute",
- "index" : 15,
+ "index" : 16,
"group" : "common"
}, {
"name" : "recordSeparatorDisabled",
@@ -11204,7 +11214,7 @@
"default" : "false",
"displayName" : "Record Separator Disabled",
"kind" : "attribute",
- "index" : 16,
+ "index" : 17,
"group" : "advanced",
"label" : "advanced"
}, {
@@ -11214,7 +11224,7 @@
"title" : "Record Separator",
"displayName" : "Record Separator",
"kind" : "attribute",
- "index" : 17,
+ "index" : 18,
"group" : "common"
}, {
"name" : "skipHeaderRecord",
@@ -11224,7 +11234,7 @@
"default" : "false",
"displayName" : "Skip Header Record",
"kind" : "attribute",
- "index" : 18,
+ "index" : 19,
"group" : "common"
}, {
"name" : "quoteMode",
@@ -11234,7 +11244,7 @@
"title" : "Quote Mode",
"displayName" : "Quote Mode",
"kind" : "attribute",
- "index" : 19,
+ "index" : 20,
"group" : "common"
}, {
"name" : "ignoreHeaderCase",
@@ -11244,7 +11254,7 @@
"default" : "false",
"displayName" : "Ignore Header Case",
"kind" : "attribute",
- "index" : 20,
+ "index" : 21,
"group" : "common"
}, {
"name" : "trim",
@@ -11254,7 +11264,7 @@
"default" : "false",
"displayName" : "Trim",
"kind" : "attribute",
- "index" : 21,
+ "index" : 22,
"group" : "common"
}, {
"name" : "trailingDelimiter",
@@ -11264,7 +11274,7 @@
"default" : "false",
"displayName" : "Trailing Delimiter",
"kind" : "attribute",
- "index" : 22,
+ "index" : 23,
"group" : "common"
}, {
"name" : "marshallerFactoryRef",
@@ -11273,7 +11283,7 @@
"title" : "Marshaller Factory Ref",
"displayName" : "Marshaller Factory Ref",
"kind" : "attribute",
- "index" : 23,
+ "index" : 24,
"group" : "advanced",
"label" : "advanced"
}, {
@@ -11284,7 +11294,7 @@
"default" : "false",
"displayName" : "Lazy Load",
"kind" : "attribute",
- "index" : 24,
+ "index" : 25,
"group" : "advanced",
"label" : "advanced"
}, {
@@ -11295,7 +11305,7 @@
"default" : "false",
"displayName" : "Use Maps",
"kind" : "attribute",
- "index" : 25,
+ "index" : 26,
"group" : "common"
}, {
"name" : "useOrderedMaps",
@@ -11305,7 +11315,7 @@
"default" : "false",
"displayName" : "Use Ordered Maps",
"kind" : "attribute",
- "index" : 26,
+ "index" : 27,
"group" : "common"
}, {
"name" : "recordConverterRef",
@@ -11314,7 +11324,7 @@
"title" : "Record Converter Ref",
"displayName" : "Record Converter Ref",
"kind" : "attribute",
- "index" : 27,
+ "index" : 28,
"group" : "advanced",
"label" : "advanced"
}, {
@@ -11325,7 +11335,7 @@
"default" : "false",
"displayName" : "Capture Header Record",
"kind" : "attribute",
- "index" : 28,
+ "index" : 29,
"group" : "advanced",
"label" : "advanced"
} ]
diff --git
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json
index 4bfd92cb17ff..a48b0d377f2e 100644
---
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json
+++
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json
@@ -8959,6 +8959,12 @@
"description" : "Whether to disable headers.",
"default" : false
},
+ "headerFromMapKeys" : {
+ "type" : "boolean",
+ "title" : "Header From Map Keys",
+ "description" : "When marshalling a Map, or a List of Maps, and
no header is configured, whether to write a header line with the keys of the
first Map. The keys of the first Map are then the columns of all the rows, as
with the header option: a key that only later rows have is not written.",
+ "default" : false
+ },
"id" : {
"type" : "string",
"title" : "Id",