This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch bindy in repository https://gitbox.apache.org/repos/asf/camel.git
commit 9e4a48f04e53ed7de854be6c6a9bfe6f93816e50 Author: Claus Ibsen <[email protected]> AuthorDate: Sun Dec 28 14:45:35 2025 +0100 CAMEL-12941: camel-bindy - Add option to use null as default value for string types --- .../apache/camel/catalog/dataformats/bindyCsv.json | 7 +- .../camel/catalog/dataformats/bindyFixed.json | 7 +- .../apache/camel/catalog/dataformats/bindyKvp.json | 7 +- .../org/apache/camel/catalog/models/bindy.json | 7 +- .../apache/camel/catalog/schemas/camel-spring.xsd | 9 +++ .../apache/camel/catalog/schemas/camel-xml-io.xsd | 9 +++ .../bindy/csv/BindyCsvDataFormatConfigurer.java | 7 ++ .../BindyFixedLengthDataFormatConfigurer.java | 7 ++ .../kvp/BindyKeyValuePairDataFormatConfigurer.java | 7 ++ .../camel/dataformat/bindy/csv/bindyCsv.json | 7 +- .../camel/dataformat/bindy/fixed/bindyFixed.json | 7 +- .../camel/dataformat/bindy/kvp/bindyKvp.json | 7 +- .../dataformat/bindy/BindyAbstractDataFormat.java | 9 +++ .../dataformat/bindy/BindyAbstractFactory.java | 13 +++- .../camel/dataformat/bindy/BindyCsvFactory.java | 3 +- .../dataformat/bindy/BindyFixedLengthFactory.java | 2 +- .../dataformat/bindy/BindyKeyValuePairFactory.java | 11 +-- .../dataformat/bindy/csv/BindyCsvDataFormat.java | 2 + .../bindy/fixed/BindyFixedLengthDataFormat.java | 2 + .../bindy/kvp/BindyKeyValuePairDataFormat.java | 2 + .../csv/BindyCsvStringDefaultValueAsNullTest.java | 89 ++++++++++++++++++++++ .../org/apache/camel/model/dataformat/bindy.json | 7 +- .../camel/model/dataformat/BindyDataFormat.java | 41 ++++++++++ .../reifier/dataformat/BindyDataFormatReifier.java | 1 + .../java/org/apache/camel/xml/in/ModelParser.java | 1 + .../java/org/apache/camel/xml/out/ModelWriter.java | 1 + .../org/apache/camel/yaml/out/ModelWriter.java | 1 + .../dsl/yaml/deserializers/ModelDeserializers.java | 6 ++ .../generated/resources/schema/camelYamlDsl.json | 6 ++ 29 files changed, 252 insertions(+), 33 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/bindyCsv.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/bindyCsv.json index 3cfd47c433f5..9b38f3e4a6ca 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/bindyCsv.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/bindyCsv.json @@ -19,8 +19,9 @@ "id": { "index": 0, "kind": "attribute", "displayName": "Id", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The id of this node" }, "type": { "index": 1, "kind": "attribute", "displayName": "Type", "group": "common", "required": true, "type": "enum", "javaType": "org.apache.camel.model.dataformat.BindyType", "enum": [ "Csv", "Fixed", "KeyValue" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "Csv", "description": "Whether to use Csv, Fixed, or KeyValue." }, "classType": { "index": 2, "kind": "attribute", "displayName": "Class Type", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of model class to use." }, - "allowEmptyStream": { "index": 3, "kind": "attribute", "displayName": "Allow Empty Stream", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to allow empty streams in the unmarshal process. If true, no exception will be thrown when a body without records is provided." }, - "unwrapSingleInstance": { "index": 4, "kind": "attribute", "displayName": "Unwrap Single Instance", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "When unmarshalling should a single instance be unwrapped and returned instead of wrapped in a java.util.List." }, - "locale": { "index": 5, "kind": "attribute", "displayName": "Locale", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To configure a default locale to use, such as us for united states. To use the JVM platform default locale then use the name default" } + "defaultValueStringAsNull": { "index": 3, "kind": "attribute", "displayName": "Default Value String As Null", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "To change the default value for string types to be null instead of an empty string." }, + "allowEmptyStream": { "index": 4, "kind": "attribute", "displayName": "Allow Empty Stream", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to allow empty streams in the unmarshal process. If true, no exception will be thrown when a body without records is provided." }, + "unwrapSingleInstance": { "index": 5, "kind": "attribute", "displayName": "Unwrap Single Instance", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "When unmarshalling should a single instance be unwrapped and returned instead of wrapped in a java.util.List." }, + "locale": { "index": 6, "kind": "attribute", "displayName": "Locale", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To configure a default locale to use, such as us for united states. To use the JVM platform default locale then use the name default" } } } diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/bindyFixed.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/bindyFixed.json index ade37abcfd1f..49640bcfde6c 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/bindyFixed.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/bindyFixed.json @@ -19,8 +19,9 @@ "id": { "index": 0, "kind": "attribute", "displayName": "Id", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The id of this node" }, "type": { "index": 1, "kind": "attribute", "displayName": "Type", "group": "common", "required": true, "type": "enum", "javaType": "org.apache.camel.model.dataformat.BindyType", "enum": [ "Csv", "Fixed", "KeyValue" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "Fixed", "description": "Whether to use Csv, Fixed, or KeyValue." }, "classType": { "index": 2, "kind": "attribute", "displayName": "Class Type", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of model class to use." }, - "allowEmptyStream": { "index": 3, "kind": "attribute", "displayName": "Allow Empty Stream", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to allow empty streams in the unmarshal process. If true, no exception will be thrown when a body without records is provided." }, - "unwrapSingleInstance": { "index": 4, "kind": "attribute", "displayName": "Unwrap Single Instance", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "When unmarshalling should a single instance be unwrapped and returned instead of wrapped in a java.util.List." }, - "locale": { "index": 5, "kind": "attribute", "displayName": "Locale", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To configure a default locale to use, such as us for united states. To use the JVM platform default locale then use the name default" } + "defaultValueStringAsNull": { "index": 3, "kind": "attribute", "displayName": "Default Value String As Null", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "To change the default value for string types to be null instead of an empty string." }, + "allowEmptyStream": { "index": 4, "kind": "attribute", "displayName": "Allow Empty Stream", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to allow empty streams in the unmarshal process. If true, no exception will be thrown when a body without records is provided." }, + "unwrapSingleInstance": { "index": 5, "kind": "attribute", "displayName": "Unwrap Single Instance", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "When unmarshalling should a single instance be unwrapped and returned instead of wrapped in a java.util.List." }, + "locale": { "index": 6, "kind": "attribute", "displayName": "Locale", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To configure a default locale to use, such as us for united states. To use the JVM platform default locale then use the name default" } } } diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/bindyKvp.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/bindyKvp.json index 8c3e6c2546f9..b3990f45eddb 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/bindyKvp.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/bindyKvp.json @@ -19,8 +19,9 @@ "id": { "index": 0, "kind": "attribute", "displayName": "Id", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The id of this node" }, "type": { "index": 1, "kind": "attribute", "displayName": "Type", "group": "common", "required": true, "type": "enum", "javaType": "org.apache.camel.model.dataformat.BindyType", "enum": [ "Csv", "Fixed", "KeyValue" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "KeyValue", "description": "Whether to use Csv, Fixed, or KeyValue." }, "classType": { "index": 2, "kind": "attribute", "displayName": "Class Type", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of model class to use." }, - "allowEmptyStream": { "index": 3, "kind": "attribute", "displayName": "Allow Empty Stream", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to allow empty streams in the unmarshal process. If true, no exception will be thrown when a body without records is provided." }, - "unwrapSingleInstance": { "index": 4, "kind": "attribute", "displayName": "Unwrap Single Instance", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "When unmarshalling should a single instance be unwrapped and returned instead of wrapped in a java.util.List." }, - "locale": { "index": 5, "kind": "attribute", "displayName": "Locale", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To configure a default locale to use, such as us for united states. To use the JVM platform default locale then use the name default" } + "defaultValueStringAsNull": { "index": 3, "kind": "attribute", "displayName": "Default Value String As Null", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "To change the default value for string types to be null instead of an empty string." }, + "allowEmptyStream": { "index": 4, "kind": "attribute", "displayName": "Allow Empty Stream", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to allow empty streams in the unmarshal process. If true, no exception will be thrown when a body without records is provided." }, + "unwrapSingleInstance": { "index": 5, "kind": "attribute", "displayName": "Unwrap Single Instance", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "When unmarshalling should a single instance be unwrapped and returned instead of wrapped in a java.util.List." }, + "locale": { "index": 6, "kind": "attribute", "displayName": "Locale", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To configure a default locale to use, such as us for united states. To use the JVM platform default locale then use the name default" } } } diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/bindy.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/bindy.json index ed8ce02c8bc5..2fada12392f1 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/bindy.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/bindy.json @@ -16,8 +16,9 @@ "id": { "index": 0, "kind": "attribute", "displayName": "Id", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The id of this node" }, "type": { "index": 1, "kind": "attribute", "displayName": "Type", "group": "common", "required": true, "type": "enum", "javaType": "org.apache.camel.model.dataformat.BindyType", "enum": [ "Csv", "Fixed", "KeyValue" ], "deprecated": false, "autowired": false, "secret": false, "description": "Whether to use Csv, Fixed, or KeyValue." }, "classType": { "index": 2, "kind": "attribute", "displayName": "Class Type", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of model class to use." }, - "allowEmptyStream": { "index": 3, "kind": "attribute", "displayName": "Allow Empty Stream", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to allow empty streams in the unmarshal process. If true, no exception will be thrown when a body without records is provided." }, - "unwrapSingleInstance": { "index": 4, "kind": "attribute", "displayName": "Unwrap Single Instance", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "When unmarshalling should a single instance be unwrapped and returned instead of wrapped in a java.util.List." }, - "locale": { "index": 5, "kind": "attribute", "displayName": "Locale", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To configure a default locale to use, such as us for united states. To use the JVM platform default locale then use the name default" } + "defaultValueStringAsNull": { "index": 3, "kind": "attribute", "displayName": "Default Value String As Null", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "To change the default value for string types to be null instead of an empty string." }, + "allowEmptyStream": { "index": 4, "kind": "attribute", "displayName": "Allow Empty Stream", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to allow empty streams in the unmarshal process. If true, no exception will be thrown when a body without records is provided." }, + "unwrapSingleInstance": { "index": 5, "kind": "attribute", "displayName": "Unwrap Single Instance", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "When unmarshalling should a single instance be unwrapped and returned instead of wrapped in a java.util.List." }, + "locale": { "index": 6, "kind": "attribute", "displayName": "Locale", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To configure a default locale to use, such as us for united states. To use the JVM platform default locale then use the name default" } } } 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 b3d10e2eb135..fa6796c0b9fa 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 @@ -8070,6 +8070,15 @@ Whether to use Csv, Fixed, or KeyValue. <xs:documentation xml:lang="en"> <![CDATA[ Name of model class to use. +]]> + </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="defaultValueStringAsNull" type="xs:string"> + <xs:annotation> + <xs:documentation xml:lang="en"> +<![CDATA[ +To change the default value for string types to be null instead of an empty string. 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 d0ea0a2d90bb..03ac2e467303 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 @@ -6743,6 +6743,15 @@ Whether to use Csv, Fixed, or KeyValue. <xs:documentation xml:lang="en"> <![CDATA[ Name of model class to use. +]]> + </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="defaultValueStringAsNull" type="xs:string"> + <xs:annotation> + <xs:documentation xml:lang="en"> +<![CDATA[ +To change the default value for string types to be null instead of an empty string. Default value: false ]]> </xs:documentation> </xs:annotation> diff --git a/components/camel-bindy/src/generated/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormatConfigurer.java b/components/camel-bindy/src/generated/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormatConfigurer.java index 5bbb3c149039..00d603319d9a 100644 --- a/components/camel-bindy/src/generated/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormatConfigurer.java +++ b/components/camel-bindy/src/generated/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormatConfigurer.java @@ -24,6 +24,7 @@ public class BindyCsvDataFormatConfigurer extends org.apache.camel.support.compo Map<String, Object> map = new CaseInsensitiveMap(); map.put("AllowEmptyStream", boolean.class); map.put("ClassType", java.lang.Class.class); + map.put("DefaultValueStringAsNull", boolean.class); map.put("Locale", java.lang.String.class); map.put("UnwrapSingleInstance", boolean.class); ALL_OPTIONS = map; @@ -37,6 +38,8 @@ public class BindyCsvDataFormatConfigurer extends org.apache.camel.support.compo case "allowEmptyStream": target.setAllowEmptyStream(property(camelContext, boolean.class, value)); return true; case "classtype": case "classType": target.setClassType(property(camelContext, java.lang.Class.class, value)); return true; + case "defaultvaluestringasnull": + case "defaultValueStringAsNull": target.setDefaultValueStringAsNull(property(camelContext, boolean.class, value)); return true; case "locale": target.setLocale(property(camelContext, java.lang.String.class, value)); return true; case "unwrapsingleinstance": case "unwrapSingleInstance": target.setUnwrapSingleInstance(property(camelContext, boolean.class, value)); return true; @@ -56,6 +59,8 @@ public class BindyCsvDataFormatConfigurer extends org.apache.camel.support.compo case "allowEmptyStream": return boolean.class; case "classtype": case "classType": return java.lang.Class.class; + case "defaultvaluestringasnull": + case "defaultValueStringAsNull": return boolean.class; case "locale": return java.lang.String.class; case "unwrapsingleinstance": case "unwrapSingleInstance": return boolean.class; @@ -71,6 +76,8 @@ public class BindyCsvDataFormatConfigurer extends org.apache.camel.support.compo case "allowEmptyStream": return target.isAllowEmptyStream(); case "classtype": case "classType": return target.getClassType(); + case "defaultvaluestringasnull": + case "defaultValueStringAsNull": return target.isDefaultValueStringAsNull(); case "locale": return target.getLocale(); case "unwrapsingleinstance": case "unwrapSingleInstance": return target.isUnwrapSingleInstance(); diff --git a/components/camel-bindy/src/generated/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormatConfigurer.java b/components/camel-bindy/src/generated/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormatConfigurer.java index 20c11ef151cc..caa4898e96d4 100644 --- a/components/camel-bindy/src/generated/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormatConfigurer.java +++ b/components/camel-bindy/src/generated/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormatConfigurer.java @@ -24,6 +24,7 @@ public class BindyFixedLengthDataFormatConfigurer extends org.apache.camel.suppo Map<String, Object> map = new CaseInsensitiveMap(); map.put("AllowEmptyStream", boolean.class); map.put("ClassType", java.lang.Class.class); + map.put("DefaultValueStringAsNull", boolean.class); map.put("Locale", java.lang.String.class); map.put("UnwrapSingleInstance", boolean.class); ALL_OPTIONS = map; @@ -37,6 +38,8 @@ public class BindyFixedLengthDataFormatConfigurer extends org.apache.camel.suppo case "allowEmptyStream": target.setAllowEmptyStream(property(camelContext, boolean.class, value)); return true; case "classtype": case "classType": target.setClassType(property(camelContext, java.lang.Class.class, value)); return true; + case "defaultvaluestringasnull": + case "defaultValueStringAsNull": target.setDefaultValueStringAsNull(property(camelContext, boolean.class, value)); return true; case "locale": target.setLocale(property(camelContext, java.lang.String.class, value)); return true; case "unwrapsingleinstance": case "unwrapSingleInstance": target.setUnwrapSingleInstance(property(camelContext, boolean.class, value)); return true; @@ -56,6 +59,8 @@ public class BindyFixedLengthDataFormatConfigurer extends org.apache.camel.suppo case "allowEmptyStream": return boolean.class; case "classtype": case "classType": return java.lang.Class.class; + case "defaultvaluestringasnull": + case "defaultValueStringAsNull": return boolean.class; case "locale": return java.lang.String.class; case "unwrapsingleinstance": case "unwrapSingleInstance": return boolean.class; @@ -71,6 +76,8 @@ public class BindyFixedLengthDataFormatConfigurer extends org.apache.camel.suppo case "allowEmptyStream": return target.isAllowEmptyStream(); case "classtype": case "classType": return target.getClassType(); + case "defaultvaluestringasnull": + case "defaultValueStringAsNull": return target.isDefaultValueStringAsNull(); case "locale": return target.getLocale(); case "unwrapsingleinstance": case "unwrapSingleInstance": return target.isUnwrapSingleInstance(); diff --git a/components/camel-bindy/src/generated/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormatConfigurer.java b/components/camel-bindy/src/generated/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormatConfigurer.java index c63dcfd8083f..ab6e2cb7f3e2 100644 --- a/components/camel-bindy/src/generated/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormatConfigurer.java +++ b/components/camel-bindy/src/generated/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormatConfigurer.java @@ -24,6 +24,7 @@ public class BindyKeyValuePairDataFormatConfigurer extends org.apache.camel.supp Map<String, Object> map = new CaseInsensitiveMap(); map.put("AllowEmptyStream", boolean.class); map.put("ClassType", java.lang.Class.class); + map.put("DefaultValueStringAsNull", boolean.class); map.put("Locale", java.lang.String.class); map.put("UnwrapSingleInstance", boolean.class); ALL_OPTIONS = map; @@ -37,6 +38,8 @@ public class BindyKeyValuePairDataFormatConfigurer extends org.apache.camel.supp case "allowEmptyStream": target.setAllowEmptyStream(property(camelContext, boolean.class, value)); return true; case "classtype": case "classType": target.setClassType(property(camelContext, java.lang.Class.class, value)); return true; + case "defaultvaluestringasnull": + case "defaultValueStringAsNull": target.setDefaultValueStringAsNull(property(camelContext, boolean.class, value)); return true; case "locale": target.setLocale(property(camelContext, java.lang.String.class, value)); return true; case "unwrapsingleinstance": case "unwrapSingleInstance": target.setUnwrapSingleInstance(property(camelContext, boolean.class, value)); return true; @@ -56,6 +59,8 @@ public class BindyKeyValuePairDataFormatConfigurer extends org.apache.camel.supp case "allowEmptyStream": return boolean.class; case "classtype": case "classType": return java.lang.Class.class; + case "defaultvaluestringasnull": + case "defaultValueStringAsNull": return boolean.class; case "locale": return java.lang.String.class; case "unwrapsingleinstance": case "unwrapSingleInstance": return boolean.class; @@ -71,6 +76,8 @@ public class BindyKeyValuePairDataFormatConfigurer extends org.apache.camel.supp case "allowEmptyStream": return target.isAllowEmptyStream(); case "classtype": case "classType": return target.getClassType(); + case "defaultvaluestringasnull": + case "defaultValueStringAsNull": return target.isDefaultValueStringAsNull(); case "locale": return target.getLocale(); case "unwrapsingleinstance": case "unwrapSingleInstance": return target.isUnwrapSingleInstance(); diff --git a/components/camel-bindy/src/generated/resources/META-INF/org/apache/camel/dataformat/bindy/csv/bindyCsv.json b/components/camel-bindy/src/generated/resources/META-INF/org/apache/camel/dataformat/bindy/csv/bindyCsv.json index 3cfd47c433f5..9b38f3e4a6ca 100644 --- a/components/camel-bindy/src/generated/resources/META-INF/org/apache/camel/dataformat/bindy/csv/bindyCsv.json +++ b/components/camel-bindy/src/generated/resources/META-INF/org/apache/camel/dataformat/bindy/csv/bindyCsv.json @@ -19,8 +19,9 @@ "id": { "index": 0, "kind": "attribute", "displayName": "Id", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The id of this node" }, "type": { "index": 1, "kind": "attribute", "displayName": "Type", "group": "common", "required": true, "type": "enum", "javaType": "org.apache.camel.model.dataformat.BindyType", "enum": [ "Csv", "Fixed", "KeyValue" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "Csv", "description": "Whether to use Csv, Fixed, or KeyValue." }, "classType": { "index": 2, "kind": "attribute", "displayName": "Class Type", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of model class to use." }, - "allowEmptyStream": { "index": 3, "kind": "attribute", "displayName": "Allow Empty Stream", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to allow empty streams in the unmarshal process. If true, no exception will be thrown when a body without records is provided." }, - "unwrapSingleInstance": { "index": 4, "kind": "attribute", "displayName": "Unwrap Single Instance", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "When unmarshalling should a single instance be unwrapped and returned instead of wrapped in a java.util.List." }, - "locale": { "index": 5, "kind": "attribute", "displayName": "Locale", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To configure a default locale to use, such as us for united states. To use the JVM platform default locale then use the name default" } + "defaultValueStringAsNull": { "index": 3, "kind": "attribute", "displayName": "Default Value String As Null", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "To change the default value for string types to be null instead of an empty string." }, + "allowEmptyStream": { "index": 4, "kind": "attribute", "displayName": "Allow Empty Stream", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to allow empty streams in the unmarshal process. If true, no exception will be thrown when a body without records is provided." }, + "unwrapSingleInstance": { "index": 5, "kind": "attribute", "displayName": "Unwrap Single Instance", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "When unmarshalling should a single instance be unwrapped and returned instead of wrapped in a java.util.List." }, + "locale": { "index": 6, "kind": "attribute", "displayName": "Locale", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To configure a default locale to use, such as us for united states. To use the JVM platform default locale then use the name default" } } } diff --git a/components/camel-bindy/src/generated/resources/META-INF/org/apache/camel/dataformat/bindy/fixed/bindyFixed.json b/components/camel-bindy/src/generated/resources/META-INF/org/apache/camel/dataformat/bindy/fixed/bindyFixed.json index ade37abcfd1f..49640bcfde6c 100644 --- a/components/camel-bindy/src/generated/resources/META-INF/org/apache/camel/dataformat/bindy/fixed/bindyFixed.json +++ b/components/camel-bindy/src/generated/resources/META-INF/org/apache/camel/dataformat/bindy/fixed/bindyFixed.json @@ -19,8 +19,9 @@ "id": { "index": 0, "kind": "attribute", "displayName": "Id", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The id of this node" }, "type": { "index": 1, "kind": "attribute", "displayName": "Type", "group": "common", "required": true, "type": "enum", "javaType": "org.apache.camel.model.dataformat.BindyType", "enum": [ "Csv", "Fixed", "KeyValue" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "Fixed", "description": "Whether to use Csv, Fixed, or KeyValue." }, "classType": { "index": 2, "kind": "attribute", "displayName": "Class Type", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of model class to use." }, - "allowEmptyStream": { "index": 3, "kind": "attribute", "displayName": "Allow Empty Stream", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to allow empty streams in the unmarshal process. If true, no exception will be thrown when a body without records is provided." }, - "unwrapSingleInstance": { "index": 4, "kind": "attribute", "displayName": "Unwrap Single Instance", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "When unmarshalling should a single instance be unwrapped and returned instead of wrapped in a java.util.List." }, - "locale": { "index": 5, "kind": "attribute", "displayName": "Locale", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To configure a default locale to use, such as us for united states. To use the JVM platform default locale then use the name default" } + "defaultValueStringAsNull": { "index": 3, "kind": "attribute", "displayName": "Default Value String As Null", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "To change the default value for string types to be null instead of an empty string." }, + "allowEmptyStream": { "index": 4, "kind": "attribute", "displayName": "Allow Empty Stream", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to allow empty streams in the unmarshal process. If true, no exception will be thrown when a body without records is provided." }, + "unwrapSingleInstance": { "index": 5, "kind": "attribute", "displayName": "Unwrap Single Instance", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "When unmarshalling should a single instance be unwrapped and returned instead of wrapped in a java.util.List." }, + "locale": { "index": 6, "kind": "attribute", "displayName": "Locale", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To configure a default locale to use, such as us for united states. To use the JVM platform default locale then use the name default" } } } diff --git a/components/camel-bindy/src/generated/resources/META-INF/org/apache/camel/dataformat/bindy/kvp/bindyKvp.json b/components/camel-bindy/src/generated/resources/META-INF/org/apache/camel/dataformat/bindy/kvp/bindyKvp.json index 8c3e6c2546f9..b3990f45eddb 100644 --- a/components/camel-bindy/src/generated/resources/META-INF/org/apache/camel/dataformat/bindy/kvp/bindyKvp.json +++ b/components/camel-bindy/src/generated/resources/META-INF/org/apache/camel/dataformat/bindy/kvp/bindyKvp.json @@ -19,8 +19,9 @@ "id": { "index": 0, "kind": "attribute", "displayName": "Id", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The id of this node" }, "type": { "index": 1, "kind": "attribute", "displayName": "Type", "group": "common", "required": true, "type": "enum", "javaType": "org.apache.camel.model.dataformat.BindyType", "enum": [ "Csv", "Fixed", "KeyValue" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "KeyValue", "description": "Whether to use Csv, Fixed, or KeyValue." }, "classType": { "index": 2, "kind": "attribute", "displayName": "Class Type", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of model class to use." }, - "allowEmptyStream": { "index": 3, "kind": "attribute", "displayName": "Allow Empty Stream", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to allow empty streams in the unmarshal process. If true, no exception will be thrown when a body without records is provided." }, - "unwrapSingleInstance": { "index": 4, "kind": "attribute", "displayName": "Unwrap Single Instance", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "When unmarshalling should a single instance be unwrapped and returned instead of wrapped in a java.util.List." }, - "locale": { "index": 5, "kind": "attribute", "displayName": "Locale", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To configure a default locale to use, such as us for united states. To use the JVM platform default locale then use the name default" } + "defaultValueStringAsNull": { "index": 3, "kind": "attribute", "displayName": "Default Value String As Null", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "To change the default value for string types to be null instead of an empty string." }, + "allowEmptyStream": { "index": 4, "kind": "attribute", "displayName": "Allow Empty Stream", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to allow empty streams in the unmarshal process. If true, no exception will be thrown when a body without records is provided." }, + "unwrapSingleInstance": { "index": 5, "kind": "attribute", "displayName": "Unwrap Single Instance", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "When unmarshalling should a single instance be unwrapped and returned instead of wrapped in a java.util.List." }, + "locale": { "index": 6, "kind": "attribute", "displayName": "Locale", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To configure a default locale to use, such as us for united states. To use the JVM platform default locale then use the name default" } } } diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractDataFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractDataFormat.java index 9e39fe187aea..2be9f975da51 100644 --- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractDataFormat.java +++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractDataFormat.java @@ -51,6 +51,7 @@ public abstract class BindyAbstractDataFormat extends ServiceSupport implements private CamelContext camelContext; private boolean unwrapSingleInstance = true; private boolean allowEmptyStream; + private boolean defaultValueStringAsNull; protected BindyAbstractDataFormat() { } @@ -91,6 +92,14 @@ public abstract class BindyAbstractDataFormat extends ServiceSupport implements this.allowEmptyStream = allowEmptyStream; } + public boolean isDefaultValueStringAsNull() { + return defaultValueStringAsNull; + } + + public void setDefaultValueStringAsNull(boolean defaultValueStringAsNull) { + this.defaultValueStringAsNull = defaultValueStringAsNull; + } + public BindyAbstractFactory getFactory() throws Exception { if (modelFactory == null) { FormatFactory formatFactory = createFormatFactory(); diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java index 7821be29b43a..add9f55cffe8 100644 --- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java +++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java @@ -49,6 +49,7 @@ public abstract class BindyAbstractFactory implements BindyFactory { private String locale; private Class<?> type; + private boolean defaultValueStringAsNull; protected BindyAbstractFactory(Class<?> type) throws Exception { this.type = type; @@ -214,7 +215,7 @@ public abstract class BindyAbstractFactory implements BindyFactory { return nf; } - public static Object getDefaultValueForPrimitive(Class<?> clazz) { + public static Object getDefaultValueForPrimitive(Class<?> clazz, boolean defaultValueStringAsNull) { if (clazz == byte.class) { return Byte.MIN_VALUE; } else if (clazz == short.class) { @@ -232,7 +233,7 @@ public abstract class BindyAbstractFactory implements BindyFactory { } else if (clazz == boolean.class) { return false; } else if (clazz == String.class) { - return ""; + return defaultValueStringAsNull ? null : ""; } else { return null; } @@ -282,4 +283,12 @@ public abstract class BindyAbstractFactory implements BindyFactory { public void setFormatFactory(FormatFactory formatFactory) { this.formatFactory = formatFactory; } + + public boolean isDefaultValueStringAsNull() { + return defaultValueStringAsNull; + } + + public void setDefaultValueStringAsNull(boolean defaultValueStringAsNull) { + this.defaultValueStringAsNull = defaultValueStringAsNull; + } } diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java index ab7fc5faa43d..9c095e08402a 100644 --- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java +++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java @@ -270,7 +270,7 @@ public class BindyCsvFactory extends BindyAbstractFactory implements BindyFactor if (!dataField.defaultValue().isEmpty()) { value = format.parse(dataField.defaultValue()); } else { - value = getDefaultValueForPrimitive(field.getType()); + value = getDefaultValueForPrimitive(field.getType(), isDefaultValueStringAsNull()); } } @@ -802,4 +802,5 @@ public class BindyCsvFactory extends BindyAbstractFactory implements BindyFactor public boolean isTrimLine() { return trimLine; } + } diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java index ea9c5efbefda..6524eebf1941 100644 --- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java +++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java @@ -288,7 +288,7 @@ public class BindyFixedLengthFactory extends BindyAbstractFactory implements Bin e); } } else { - value = getDefaultValueForPrimitive(field.getType()); + value = getDefaultValueForPrimitive(field.getType(), isDefaultValueStringAsNull()); } if (value != null && !dataField.method().isEmpty()) { diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java index cbba5a2cace1..70d38f0eec27 100644 --- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java +++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java @@ -214,7 +214,7 @@ public class BindyKeyValuePairFactory extends BindyAbstractFactory implements Bi throw new IllegalArgumentException("The mandatory key/tag : " + key + " has not been defined !"); } - Object result = getDefaultValueForPrimitive(field.getType()); + Object result = getDefaultValueForPrimitive(field.getType(), isDefaultValueStringAsNull()); try { field.set(obj, result); @@ -243,7 +243,7 @@ public class BindyKeyValuePairFactory extends BindyAbstractFactory implements Bi obj = clazz.newInstance(); } - Object result = getDefaultValueForPrimitive(field.getType()); + Object result = getDefaultValueForPrimitive(field.getType(), isDefaultValueStringAsNull()); try { field.set(obj, result); } catch (Exception e) { @@ -299,7 +299,7 @@ public class BindyKeyValuePairFactory extends BindyAbstractFactory implements Bi LOG.debug("Value formated : {}", result); } else { - result = getDefaultValueForPrimitive(field.getType()); + result = getDefaultValueForPrimitive(field.getType(), isDefaultValueStringAsNull()); } try { field.set(obj, result); @@ -344,7 +344,8 @@ public class BindyKeyValuePairFactory extends BindyAbstractFactory implements Bi if (value != null) { field.set(obj, result); } else { - field.set(obj, getDefaultValueForPrimitive(field.getType())); + field.set(obj, + getDefaultValueForPrimitive(field.getType(), isDefaultValueStringAsNull())); } } catch (Exception e) { throw new IllegalArgumentException( @@ -376,7 +377,7 @@ public class BindyKeyValuePairFactory extends BindyAbstractFactory implements Bi } else { // No values found from message - Object result = getDefaultValueForPrimitive(field.getType()); + Object result = getDefaultValueForPrimitive(field.getType(), isDefaultValueStringAsNull()); try { field.set(obj, result); diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java index 03328b10d089..6c38ec2d92a1 100644 --- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java +++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java @@ -394,6 +394,8 @@ public class BindyCsvDataFormat extends BindyAbstractDataFormat { protected BindyAbstractFactory createModelFactory(FormatFactory formatFactory) throws Exception { BindyCsvFactory bindyCsvFactory = new BindyCsvFactory(getClassType()); bindyCsvFactory.setFormatFactory(formatFactory); + bindyCsvFactory.setDefaultValueStringAsNull(isDefaultValueStringAsNull()); + bindyCsvFactory.setLocale(getLocale()); return bindyCsvFactory; } } diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormat.java index 6bb3fa68b701..51404e36edcd 100644 --- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormat.java +++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormat.java @@ -343,6 +343,8 @@ public class BindyFixedLengthDataFormat extends BindyAbstractDataFormat { BindyFixedLengthFactory factory = new BindyFixedLengthFactory(getClassType()); factory.setFormatFactory(formatFactory); + factory.setLocale(getLocale()); + factory.setDefaultValueStringAsNull(isDefaultValueStringAsNull()); // Optionally initialize the header factory... using header model classes if (factory.hasHeader()) { diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java index 7134290c6675..25e18bf21cdf 100644 --- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java +++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java @@ -183,6 +183,8 @@ public class BindyKeyValuePairDataFormat extends BindyAbstractDataFormat { protected BindyAbstractFactory createModelFactory(FormatFactory formatFactory) throws Exception { BindyKeyValuePairFactory bindyKeyValuePairFactory = new BindyKeyValuePairFactory(getClassType()); bindyKeyValuePairFactory.setFormatFactory(formatFactory); + bindyKeyValuePairFactory.setLocale(getLocale()); + bindyKeyValuePairFactory.setDefaultValueStringAsNull(isDefaultValueStringAsNull()); return bindyKeyValuePairFactory; } } diff --git a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyCsvStringDefaultValueAsNullTest.java b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyCsvStringDefaultValueAsNullTest.java new file mode 100644 index 000000000000..3fe132d0bb06 --- /dev/null +++ b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyCsvStringDefaultValueAsNullTest.java @@ -0,0 +1,89 @@ +/* + * 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.bindy.csv; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.dataformat.bindy.model.csv.MyCsvRecord; +import org.apache.camel.model.dataformat.BindyType; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class BindyCsvStringDefaultValueAsNullTest extends CamelTestSupport { + + @Test + public void testAsStringDefaultValueAsNullTrue() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() throws Exception { + var df = dataFormat().bindy().defaultValueStringAsNull(true).type(BindyType.Csv).classType(MyCsvRecord.class) + .end(); + from("direct:fromCsv").unmarshal(df).to("mock:result"); + } + }); + + MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class); + mock.expectedMessageCount(1); + + String addressLine1 = "8506 SIX FORKS ROAD,"; + String csvLine = "\"PROBLEM SOLVER\",\"" + addressLine1 + + "\",\"SUITE 104\",\"RALEIGH\",\"\",\"27615\",\"\""; + + template.sendBody("direct:fromCsv", csvLine.trim()); + + mock.assertIsSatisfied(); + + MyCsvRecord rec = mock.getReceivedExchanges().get(0).getMessage().getBody(MyCsvRecord.class); + Assertions.assertNotNull(rec); + Assertions.assertEquals(addressLine1, rec.getAddressLine1()); + Assertions.assertNull(rec.getCountry()); + Assertions.assertNull(rec.getState()); + Assertions.assertEquals("27615", rec.getZip()); + } + + @Test + public void testAsStringDefaultValueAsNullFalse() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() throws Exception { + var df = dataFormat().bindy().defaultValueStringAsNull(false).type(BindyType.Csv).classType(MyCsvRecord.class) + .end(); + from("direct:fromCsv").unmarshal(df).to("mock:result"); + } + }); + + MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class); + mock.expectedMessageCount(1); + + String addressLine1 = "8506 SIX FORKS ROAD,"; + String csvLine = "\"PROBLEM SOLVER\",\"" + addressLine1 + + "\",\"SUITE 104\",\"RALEIGH\",\"\",\"27615\",\"\""; + + template.sendBody("direct:fromCsv", csvLine.trim()); + + mock.assertIsSatisfied(); + + MyCsvRecord rec = mock.getReceivedExchanges().get(0).getMessage().getBody(MyCsvRecord.class); + Assertions.assertNotNull(rec); + Assertions.assertEquals(addressLine1, rec.getAddressLine1()); + Assertions.assertEquals("", rec.getCountry()); + Assertions.assertEquals("", rec.getState()); + Assertions.assertEquals("27615", rec.getZip()); + } + +} diff --git a/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/bindy.json b/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/bindy.json index ed8ce02c8bc5..2fada12392f1 100644 --- a/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/bindy.json +++ b/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/bindy.json @@ -16,8 +16,9 @@ "id": { "index": 0, "kind": "attribute", "displayName": "Id", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The id of this node" }, "type": { "index": 1, "kind": "attribute", "displayName": "Type", "group": "common", "required": true, "type": "enum", "javaType": "org.apache.camel.model.dataformat.BindyType", "enum": [ "Csv", "Fixed", "KeyValue" ], "deprecated": false, "autowired": false, "secret": false, "description": "Whether to use Csv, Fixed, or KeyValue." }, "classType": { "index": 2, "kind": "attribute", "displayName": "Class Type", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of model class to use." }, - "allowEmptyStream": { "index": 3, "kind": "attribute", "displayName": "Allow Empty Stream", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to allow empty streams in the unmarshal process. If true, no exception will be thrown when a body without records is provided." }, - "unwrapSingleInstance": { "index": 4, "kind": "attribute", "displayName": "Unwrap Single Instance", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "When unmarshalling should a single instance be unwrapped and returned instead of wrapped in a java.util.List." }, - "locale": { "index": 5, "kind": "attribute", "displayName": "Locale", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To configure a default locale to use, such as us for united states. To use the JVM platform default locale then use the name default" } + "defaultValueStringAsNull": { "index": 3, "kind": "attribute", "displayName": "Default Value String As Null", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "To change the default value for string types to be null instead of an empty string." }, + "allowEmptyStream": { "index": 4, "kind": "attribute", "displayName": "Allow Empty Stream", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to allow empty streams in the unmarshal process. If true, no exception will be thrown when a body without records is provided." }, + "unwrapSingleInstance": { "index": 5, "kind": "attribute", "displayName": "Unwrap Single Instance", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "When unmarshalling should a single instance be unwrapped and returned instead of wrapped in a java.util.List." }, + "locale": { "index": 6, "kind": "attribute", "displayName": "Locale", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To configure a default locale to use, such as us for united states. To use the JVM platform default locale then use the name default" } } } diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/BindyDataFormat.java b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/BindyDataFormat.java index daf486714c0b..443501733e18 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/BindyDataFormat.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/BindyDataFormat.java @@ -45,6 +45,9 @@ public class BindyDataFormat extends DataFormatDefinition { @XmlAttribute(name = "classType") private String classTypeAsString; @XmlAttribute + @Metadata(javaType = "java.lang.Boolean") + private String defaultValueStringAsNull; + @XmlAttribute @Metadata(javaType = "java.lang.Boolean", defaultValue = "false") private String allowEmptyStream; @XmlAttribute @@ -63,6 +66,7 @@ public class BindyDataFormat extends DataFormatDefinition { this.classType = source.classType; this.type = source.type; this.classTypeAsString = source.classTypeAsString; + this.defaultValueStringAsNull = source.defaultValueStringAsNull; this.allowEmptyStream = source.allowEmptyStream; this.unwrapSingleInstance = source.unwrapSingleInstance; this.locale = source.locale; @@ -73,6 +77,7 @@ public class BindyDataFormat extends DataFormatDefinition { this.classType = builder.classType; this.type = builder.type; this.classTypeAsString = builder.classTypeAsString; + this.defaultValueStringAsNull = builder.defaultValueStringAsNull; this.allowEmptyStream = builder.allowEmptyStream; this.unwrapSingleInstance = builder.unwrapSingleInstance; this.locale = builder.locale; @@ -140,6 +145,17 @@ public class BindyDataFormat extends DataFormatDefinition { this.locale = locale; } + public String getDefaultValueStringAsNull() { + return defaultValueStringAsNull; + } + + /** + * To change the default value for string types to be null instead of an empty string. + */ + public void setDefaultValueStringAsNull(String defaultValueStringAsNull) { + this.defaultValueStringAsNull = defaultValueStringAsNull; + } + public String getUnwrapSingleInstance() { return unwrapSingleInstance; } @@ -209,6 +225,15 @@ public class BindyDataFormat extends DataFormatDefinition { return this; } + public BindyDataFormat defaultValueStringAsNull(boolean defaultValueStringAsNull) { + return defaultValueStringAsNull(Boolean.toString(defaultValueStringAsNull)); + } + + public BindyDataFormat defaultValueStringAsNull(String defaultValueStringAsNull) { + this.defaultValueStringAsNull = defaultValueStringAsNull; + return this; + } + public BindyDataFormat unwrapSingleInstance(boolean unwrapSingleInstance) { return unwrapSingleInstance(Boolean.toString(unwrapSingleInstance)); } @@ -236,6 +261,7 @@ public class BindyDataFormat extends DataFormatDefinition { private Class<?> classType; private String type; private String classTypeAsString; + private String defaultValueStringAsNull; private String allowEmptyStream; private String unwrapSingleInstance; private String locale; @@ -278,6 +304,21 @@ public class BindyDataFormat extends DataFormatDefinition { return this; } + /** + * To change the default value for string types to be null instead of an empty string. + */ + public Builder defaultValueStringAsNull(String defaultValueStringAsNull) { + this.defaultValueStringAsNull = defaultValueStringAsNull; + return this; + } + + /** + * To change the default value for string types to be null instead of an empty string. + */ + public Builder defaultValueStringAsNull(boolean defaultValueStringAsNull) { + return defaultValueStringAsNull(Boolean.toString(defaultValueStringAsNull)); + } + /** * When unmarshalling should a single instance be unwrapped and returned instead of wrapped in a * <tt>java.util.List</tt>. diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/BindyDataFormatReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/BindyDataFormatReifier.java index 20cd6e2544ca..e46b349e1733 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/BindyDataFormatReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/BindyDataFormatReifier.java @@ -43,6 +43,7 @@ public class BindyDataFormatReifier extends DataFormatReifier<BindyDataFormat> { properties.put("classType", or(definition.getClassType(), definition.getClassTypeAsString())); properties.put("unwrapSingleInstance", definition.getUnwrapSingleInstance()); properties.put("allowEmptyStream", definition.getAllowEmptyStream()); + properties.put("defaultValueStringAsNull", definition.getDefaultValueStringAsNull()); } } 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 f1ae5797889e..0dab43edf902 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 @@ -1783,6 +1783,7 @@ public class ModelParser extends BaseParser { return doParse(new BindyDataFormat(), (def, key, val) -> switch (key) { case "allowEmptyStream": def.setAllowEmptyStream(val); yield true; case "classType": def.setClassTypeAsString(val); yield true; + case "defaultValueStringAsNull": def.setDefaultValueStringAsNull(val); yield true; case "locale": def.setLocale(val); yield true; case "type": def.setType(val); yield true; case "unwrapSingleInstance": def.setUnwrapSingleInstance(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 46faea7549b1..416a78326ecd 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 @@ -2462,6 +2462,7 @@ public class ModelWriter extends BaseWriter { startElement(name); doWriteIdentifiedTypeAttributes(def); doWriteAttribute("unwrapSingleInstance", def.getUnwrapSingleInstance(), "true"); + doWriteAttribute("defaultValueStringAsNull", def.getDefaultValueStringAsNull(), null); doWriteAttribute("classType", def.getClassTypeAsString(), null); doWriteAttribute("locale", def.getLocale(), null); doWriteAttribute("type", def.getType(), null); diff --git a/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/ModelWriter.java b/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/ModelWriter.java index 4ab66c4fe127..2addf34bb22d 100644 --- a/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/ModelWriter.java +++ b/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/ModelWriter.java @@ -2462,6 +2462,7 @@ public class ModelWriter extends BaseWriter { startElement(name); doWriteIdentifiedTypeAttributes(def); doWriteAttribute("unwrapSingleInstance", def.getUnwrapSingleInstance(), "true"); + doWriteAttribute("defaultValueStringAsNull", def.getDefaultValueStringAsNull(), null); doWriteAttribute("classType", def.getClassTypeAsString(), null); doWriteAttribute("locale", def.getLocale(), null); doWriteAttribute("type", def.getType(), null); 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 ec0f1da563e7..fb3cf1a11ecc 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 @@ -1527,6 +1527,7 @@ public final class ModelDeserializers extends YamlDeserializerSupport { properties = { @YamlProperty(name = "allowEmptyStream", type = "boolean", defaultValue = "false", description = "Whether to allow empty streams in the unmarshal process. If true, no exception will be thrown when a body without records is provided.", displayName = "Allow Empty Stream"), @YamlProperty(name = "classType", type = "string", description = "Name of model class to use.", displayName = "Class Type"), + @YamlProperty(name = "defaultValueStringAsNull", type = "boolean", defaultValue = "false", description = "To change the default value for string types to be null instead of an empty string.", displayName = "Default Value String As Null"), @YamlProperty(name = "id", type = "string", description = "The id of this node", displayName = "Id"), @YamlProperty(name = "locale", type = "string", description = "To configure a default locale to use, such as us for united states. To use the JVM platform default locale then use the name default", displayName = "Locale"), @YamlProperty(name = "type", type = "enum:Csv,Fixed,KeyValue", description = "Whether to use Csv, Fixed, or KeyValue.", displayName = "Type"), @@ -1558,6 +1559,11 @@ public final class ModelDeserializers extends YamlDeserializerSupport { target.setClassTypeAsString(val); break; } + case "defaultValueStringAsNull": { + String val = asText(node); + target.setDefaultValueStringAsNull(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.json b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json index d8175092a74a..9cfed89b85a4 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 @@ -10910,6 +10910,12 @@ "title" : "Class Type", "description" : "Name of model class to use." }, + "defaultValueStringAsNull" : { + "type" : "boolean", + "title" : "Default Value String As Null", + "description" : "To change the default value for string types to be null instead of an empty string.", + "default" : false + }, "id" : { "type" : "string", "title" : "Id",
