This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 666b57bce5e36e8e67e1b4ce3bac9fc85e0f8508 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sat Jan 30 14:19:18 2021 +0100 CAMEL-16114: dataformats with unmarshal should be configurable via configurer via string class name. --- .../camel/catalog/docs/jacksonxml-dataformat.adoc | 2 +- .../catalog/docs/json-jackson-dataformat.adoc | 2 +- .../component/cbor/CBORDataFormatConfigurer.java | 4 +++ .../camel/component/cbor/CBORDataFormat.java | 30 ++++++++++++++++++- .../jackson/JacksonDataFormatConfigurer.java | 4 +-- .../camel/component/jackson/json-jackson.json | 2 +- .../src/main/docs/json-jackson-dataformat.adoc | 2 +- .../camel/component/jackson/JacksonDataFormat.java | 12 ++++++++ .../jackson/SpringJacksonJsonDataFormatTest.xml | 2 +- .../jacksonxml/JacksonXMLDataFormatConfigurer.java | 6 ++-- .../camel/component/jacksonxml/jacksonxml.json | 2 +- .../src/main/docs/jacksonxml-dataformat.adoc | 2 +- .../component/jacksonxml/JacksonXMLDataFormat.java | 26 ++++++++++++++++ .../jacksonxml/SpringJacksonJsonDataFormatTest.xml | 2 +- .../snakeyaml/SnakeYAMLDataFormatConfigurer.java | 2 ++ .../component/snakeyaml/SnakeYAMLDataFormat.java | 35 +++++++++++++++++----- .../apache/camel/model/dataformat/jacksonxml.json | 2 +- .../org/apache/camel/model/dataformat/json.json | 2 +- .../model/dataformat/JacksonXMLDataFormat.java | 14 +++++++++ .../camel/model/dataformat/JsonDataFormat.java | 14 +++++++++ .../reifier/dataformat/CBORDataFormatReifier.java | 12 ++++++-- .../dataformat/JacksonXMLDataFormatReifier.java | 6 +++- .../reifier/dataformat/JsonDataFormatReifier.java | 7 ++++- .../reifier/dataformat/YAMLDataFormatReifier.java | 8 +++-- .../java/org/apache/camel/xml/in/ModelParser.java | 4 +-- .../dataformats/pages/jacksonxml-dataformat.adoc | 2 +- .../dataformats/pages/json-jackson-dataformat.adoc | 2 +- .../ROOT/pages/camel-3x-upgrade-guide-3_8.adoc | 5 ++++ 28 files changed, 180 insertions(+), 33 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jacksonxml-dataformat.adoc b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jacksonxml-dataformat.adoc index 99345f4..0e3f5e0 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jacksonxml-dataformat.adoc +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jacksonxml-dataformat.adoc @@ -52,7 +52,7 @@ The JacksonXML dataformat supports 15 options, which are listed below. | xmlMapper | | String | Lookup and use the existing XmlMapper with the given id. | prettyPrint | false | Boolean | To enable pretty printing output nicely formatted. Is by default false. | unmarshalTypeName | | String | Class name of the java type to use when unmarshalling -| jsonView | | Class | When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has JsonView annotations +| jsonViewTypeName | | String | When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has JsonView annotations | include | | String | If you want to marshal a pojo to JSON, and the pojo has some fields with null values. And you want to skip these null values, you can set this option to NON_NULL | allowJmsType | false | Boolean | Used for JMS users to allow the JMSType header from the JMS spec to specify a FQN classname to use to unmarshal to. | collectionTypeName | | String | Refers to a custom collection type to lookup in the registry to use. This option should rarely be used, but allows to use different collection types than java.util.Collection based as default. diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/json-jackson-dataformat.adoc b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/json-jackson-dataformat.adoc index 58d90fe..f0af31f 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/json-jackson-dataformat.adoc +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/json-jackson-dataformat.adoc @@ -35,7 +35,7 @@ The JSON Jackson dataformat supports 17 options, which are listed below. | useDefaultObjectMapper | true | Boolean | Whether to lookup and use default Jackson ObjectMapper from the registry. | prettyPrint | false | Boolean | To enable pretty printing output nicely formatted. Is by default false. | unmarshalTypeName | | String | Class name of the java type to use when unmarshalling -| jsonView | | Class | When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has JsonView annotations +| jsonViewTypeName | | String | When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has JsonView annotations | include | | String | If you want to marshal a pojo to JSON, and the pojo has some fields with null values. And you want to skip these null values, you can set this option to NON_NULL | allowJmsType | false | Boolean | Used for JMS users to allow the JMSType header from the JMS spec to specify a FQN classname to use to unmarshal to. | collectionTypeName | | String | Refers to a custom collection type to lookup in the registry to use. This option should rarely be used, but allows to use different collection types than java.util.Collection based as default. diff --git a/components/camel-cbor/src/generated/java/org/apache/camel/component/cbor/CBORDataFormatConfigurer.java b/components/camel-cbor/src/generated/java/org/apache/camel/component/cbor/CBORDataFormatConfigurer.java index 7ee6d7b..9014cea 100644 --- a/components/camel-cbor/src/generated/java/org/apache/camel/component/cbor/CBORDataFormatConfigurer.java +++ b/components/camel-cbor/src/generated/java/org/apache/camel/component/cbor/CBORDataFormatConfigurer.java @@ -20,10 +20,14 @@ public class CBORDataFormatConfigurer extends PropertyConfigurerSupport implemen switch (ignoreCase ? name.toLowerCase() : name) { case "objectmapper": case "objectMapper": dataformat.setObjectMapper(property(camelContext, com.fasterxml.jackson.databind.ObjectMapper.class, value)); return true; + case "unmarshaltypename": + case "unmarshalTypeName": dataformat.setUnmarshalTypeName(property(camelContext, java.lang.String.class, value)); return true; case "usedefaultobjectmapper": case "useDefaultObjectMapper": dataformat.setUseDefaultObjectMapper(property(camelContext, boolean.class, value)); return true; case "allowunmarshalltype": case "allowUnmarshallType": dataformat.setAllowUnmarshallType(property(camelContext, boolean.class, value)); return true; + case "collectiontypename": + case "collectionTypeName": dataformat.setCollectionTypeName(property(camelContext, java.lang.String.class, value)); return true; case "uselist": case "useList": dataformat.setUseList(property(camelContext, boolean.class, value)); return true; case "prettyprint": diff --git a/components/camel-cbor/src/main/java/org/apache/camel/component/cbor/CBORDataFormat.java b/components/camel-cbor/src/main/java/org/apache/camel/component/cbor/CBORDataFormat.java index 4071747..d6d081c 100644 --- a/components/camel-cbor/src/main/java/org/apache/camel/component/cbor/CBORDataFormat.java +++ b/components/camel-cbor/src/main/java/org/apache/camel/component/cbor/CBORDataFormat.java @@ -33,25 +33,29 @@ import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.type.CollectionType; import com.fasterxml.jackson.dataformat.cbor.CBORFactory; import org.apache.camel.CamelContext; +import org.apache.camel.CamelContextAware; import org.apache.camel.Exchange; import org.apache.camel.spi.DataFormat; import org.apache.camel.spi.DataFormatName; import org.apache.camel.spi.annotations.Dataformat; import org.apache.camel.support.ObjectHelper; import org.apache.camel.support.service.ServiceSupport; +import org.apache.camel.util.CastUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Dataformat("cbor") -public class CBORDataFormat extends ServiceSupport implements DataFormat, DataFormatName { +public class CBORDataFormat extends ServiceSupport implements DataFormat, DataFormatName, CamelContextAware { private static final Logger LOG = LoggerFactory.getLogger(CBORDataFormat.class); private CamelContext camelContext; private ObjectMapper objectMapper; + private String unmarshalTypeName; private Class<?> unmarshalType; private boolean useDefaultObjectMapper = true; private boolean allowUnmarshallType; + private String collectionTypeName; private Class<? extends Collection> collectionType; private boolean useList; private boolean prettyPrint; @@ -123,6 +127,14 @@ public class CBORDataFormat extends ServiceSupport implements DataFormat, DataFo this.objectMapper = objectMapper; } + public String getUnmarshalTypeName() { + return unmarshalTypeName; + } + + public void setUnmarshalTypeName(String unmarshalTypeName) { + this.unmarshalTypeName = unmarshalTypeName; + } + public Class<?> getUnmarshalType() { return unmarshalType; } @@ -139,6 +151,14 @@ public class CBORDataFormat extends ServiceSupport implements DataFormat, DataFo this.allowUnmarshallType = allowUnmarshallType; } + public String getCollectionTypeName() { + return collectionTypeName; + } + + public void setCollectionTypeName(String collectionTypeName) { + this.collectionTypeName = collectionTypeName; + } + public Class<? extends Collection> getCollectionType() { return collectionType; } @@ -291,6 +311,14 @@ public class CBORDataFormat extends ServiceSupport implements DataFormat, DataFo protected void doInit() throws Exception { super.doInit(); + if (unmarshalTypeName != null && (unmarshalType == null)) { + unmarshalType = camelContext.getClassResolver().resolveClass(unmarshalTypeName); + } + if (collectionTypeName != null && collectionType == null) { + Class<?> clazz = camelContext.getClassResolver().resolveClass(collectionTypeName); + collectionType = CastUtils.cast(clazz); + } + if (objectMapper == null) { // lookup if there is a single default mapper we can use if (useDefaultObjectMapper && camelContext != null) { diff --git a/components/camel-jackson/src/generated/java/org/apache/camel/component/jackson/JacksonDataFormatConfigurer.java b/components/camel-jackson/src/generated/java/org/apache/camel/component/jackson/JacksonDataFormatConfigurer.java index 5ada5f8..aff952f 100644 --- a/components/camel-jackson/src/generated/java/org/apache/camel/component/jackson/JacksonDataFormatConfigurer.java +++ b/components/camel-jackson/src/generated/java/org/apache/camel/component/jackson/JacksonDataFormatConfigurer.java @@ -30,8 +30,8 @@ public class JacksonDataFormatConfigurer extends PropertyConfigurerSupport imple case "moduleRefs": dataformat.setModuleRefs(property(camelContext, java.lang.String.class, value)); return true; case "unmarshaltypename": case "unmarshalTypeName": dataformat.setUnmarshalTypeName(property(camelContext, java.lang.String.class, value)); return true; - case "jsonview": - case "jsonView": dataformat.setJsonView(property(camelContext, java.lang.Class.class, value)); return true; + case "jsonviewtypename": + case "jsonViewTypeName": dataformat.setJsonViewTypeName(property(camelContext, java.lang.String.class, value)); return true; case "include": dataformat.setInclude(property(camelContext, java.lang.String.class, value)); return true; case "prettyprint": case "prettyPrint": dataformat.setPrettyPrint(property(camelContext, boolean.class, value)); return true; diff --git a/components/camel-jackson/src/generated/resources/org/apache/camel/component/jackson/json-jackson.json b/components/camel-jackson/src/generated/resources/org/apache/camel/component/jackson/json-jackson.json index 5177a3f..9135d95 100644 --- a/components/camel-jackson/src/generated/resources/org/apache/camel/component/jackson/json-jackson.json +++ b/components/camel-jackson/src/generated/resources/org/apache/camel/component/jackson/json-jackson.json @@ -20,7 +20,7 @@ "useDefaultObjectMapper": { "kind": "attribute", "displayName": "Use Default Object Mapper", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to lookup and use default Jackson ObjectMapper from the registry." }, "prettyPrint": { "kind": "attribute", "displayName": "Pretty Print", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "To enable pretty printing output nicely formatted. Is by default false." }, "unmarshalTypeName": { "kind": "attribute", "displayName": "Unmarshal Type Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Class name of the java type to use when unmarshalling" }, - "jsonView": { "kind": "attribute", "displayName": "Json View", "required": false, "type": "string", "javaType": "java.lang.Class<java.lang.Object>", "deprecated": false, "autowired": false, "secret": false, "description": "When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has JsonView annotations" }, + "jsonViewTypeName": { "kind": "attribute", "displayName": "Json View Type Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has JsonView annotations" }, "include": { "kind": "attribute", "displayName": "Include", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "If you want to marshal a pojo to JSON, and the pojo has some fields with null values. And you want to skip these null values, you can set this option to NON_NULL" }, "allowJmsType": { "kind": "attribute", "displayName": "Allow Jms Type", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Used for JMS users to allow the JMSType header from the JMS spec to specify a FQN classname to use to unmarshal to." }, "collectionTypeName": { "kind": "attribute", "displayName": "Collection Type Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Refers to a custom collection type to lookup in the registry to use. This option should rarely be used, but allows to use different collection types than java.util.Collection based as default." }, diff --git a/components/camel-jackson/src/main/docs/json-jackson-dataformat.adoc b/components/camel-jackson/src/main/docs/json-jackson-dataformat.adoc index 58d90fe..f0af31f 100644 --- a/components/camel-jackson/src/main/docs/json-jackson-dataformat.adoc +++ b/components/camel-jackson/src/main/docs/json-jackson-dataformat.adoc @@ -35,7 +35,7 @@ The JSON Jackson dataformat supports 17 options, which are listed below. | useDefaultObjectMapper | true | Boolean | Whether to lookup and use default Jackson ObjectMapper from the registry. | prettyPrint | false | Boolean | To enable pretty printing output nicely formatted. Is by default false. | unmarshalTypeName | | String | Class name of the java type to use when unmarshalling -| jsonView | | Class | When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has JsonView annotations +| jsonViewTypeName | | String | When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has JsonView annotations | include | | String | If you want to marshal a pojo to JSON, and the pojo has some fields with null values. And you want to skip these null values, you can set this option to NON_NULL | allowJmsType | false | Boolean | Used for JMS users to allow the JMSType header from the JMS spec to specify a FQN classname to use to unmarshal to. | collectionTypeName | | String | Refers to a custom collection type to lookup in the registry to use. This option should rarely be used, but allows to use different collection types than java.util.Collection based as default. diff --git a/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JacksonDataFormat.java b/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JacksonDataFormat.java index 9ffdbc4..bcb8b9b 100644 --- a/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JacksonDataFormat.java +++ b/components/camel-jackson/src/main/java/org/apache/camel/component/jackson/JacksonDataFormat.java @@ -68,6 +68,7 @@ public class JacksonDataFormat extends ServiceSupport private String moduleRefs; private String unmarshalTypeName; private Class<?> unmarshalType; + private String jsonViewTypeName; private Class<?> jsonView; private String include; private boolean prettyPrint; @@ -243,6 +244,14 @@ public class JacksonDataFormat extends ServiceSupport this.jsonView = jsonView; } + public String getJsonViewTypeName() { + return jsonViewTypeName; + } + + public void setJsonViewTypeName(String jsonViewTypeName) { + this.jsonViewTypeName = jsonViewTypeName; + } + public String getInclude() { return include; } @@ -479,6 +488,9 @@ public class JacksonDataFormat extends ServiceSupport if (unmarshalTypeName != null && (unmarshalType == null || unmarshalType == Object.class)) { unmarshalType = camelContext.getClassResolver().resolveClass(unmarshalTypeName); } + if (jsonViewTypeName != null && jsonView == null) { + jsonView = camelContext.getClassResolver().resolveClass(jsonViewTypeName); + } if (collectionTypeName != null && collectionType == null) { Class<?> clazz = camelContext.getClassResolver().resolveClass(collectionTypeName); collectionType = CastUtils.cast(clazz); diff --git a/components/camel-jackson/src/test/resources/org/apache/camel/component/jackson/SpringJacksonJsonDataFormatTest.xml b/components/camel-jackson/src/test/resources/org/apache/camel/component/jackson/SpringJacksonJsonDataFormatTest.xml index 39a72d2..28adbc4 100644 --- a/components/camel-jackson/src/test/resources/org/apache/camel/component/jackson/SpringJacksonJsonDataFormatTest.xml +++ b/components/camel-jackson/src/test/resources/org/apache/camel/component/jackson/SpringJacksonJsonDataFormatTest.xml @@ -35,7 +35,7 @@ <!-- and this one uses our own TestPojo class as unmarshal type --> <json id="pojo" library="Jackson" unmarshalTypeName="org.apache.camel.component.jackson.TestPojo"/> <!-- in addition to our own TestPojoView class we make use of the jsonView attribute here as filter --> - <json id="view" library="Jackson" unmarshalTypeName="org.apache.camel.component.jackson.TestPojoView" jsonView="org.apache.camel.component.jackson.Views$Age"/> + <json id="view" library="Jackson" unmarshalTypeName="org.apache.camel.component.jackson.TestPojoView" jsonViewTypeName="org.apache.camel.component.jackson.Views$Age"/> </dataFormats> <route> diff --git a/components/camel-jacksonxml/src/generated/java/org/apache/camel/component/jacksonxml/JacksonXMLDataFormatConfigurer.java b/components/camel-jacksonxml/src/generated/java/org/apache/camel/component/jacksonxml/JacksonXMLDataFormatConfigurer.java index 44fd8bc..b6f0a5f 100644 --- a/components/camel-jacksonxml/src/generated/java/org/apache/camel/component/jacksonxml/JacksonXMLDataFormatConfigurer.java +++ b/components/camel-jacksonxml/src/generated/java/org/apache/camel/component/jacksonxml/JacksonXMLDataFormatConfigurer.java @@ -20,14 +20,16 @@ public class JacksonXMLDataFormatConfigurer extends PropertyConfigurerSupport im switch (ignoreCase ? name.toLowerCase() : name) { case "xmlmapper": case "xmlMapper": dataformat.setXmlMapper(property(camelContext, com.fasterxml.jackson.dataformat.xml.XmlMapper.class, value)); return true; + case "collectiontypename": + case "collectionTypeName": dataformat.setCollectionTypeName(property(camelContext, java.lang.String.class, value)); return true; case "moduleclassnames": case "moduleClassNames": dataformat.setModuleClassNames(property(camelContext, java.lang.String.class, value)); return true; case "modulerefs": case "moduleRefs": dataformat.setModuleRefs(property(camelContext, java.lang.String.class, value)); return true; case "unmarshaltypename": case "unmarshalTypeName": dataformat.setUnmarshalTypeName(property(camelContext, java.lang.String.class, value)); return true; - case "jsonview": - case "jsonView": dataformat.setJsonView(property(camelContext, java.lang.Class.class, value)); return true; + case "jsonviewtypename": + case "jsonViewTypeName": dataformat.setJsonViewTypeName(property(camelContext, java.lang.String.class, value)); return true; case "include": dataformat.setInclude(property(camelContext, java.lang.String.class, value)); return true; case "prettyprint": case "prettyPrint": dataformat.setPrettyPrint(property(camelContext, boolean.class, value)); return true; diff --git a/components/camel-jacksonxml/src/generated/resources/org/apache/camel/component/jacksonxml/jacksonxml.json b/components/camel-jacksonxml/src/generated/resources/org/apache/camel/component/jacksonxml/jacksonxml.json index 8b4c8ed..8f6a70b 100644 --- a/components/camel-jacksonxml/src/generated/resources/org/apache/camel/component/jacksonxml/jacksonxml.json +++ b/components/camel-jacksonxml/src/generated/resources/org/apache/camel/component/jacksonxml/jacksonxml.json @@ -19,7 +19,7 @@ "xmlMapper": { "kind": "attribute", "displayName": "Xml Mapper", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Lookup and use the existing XmlMapper with the given id." }, "prettyPrint": { "kind": "attribute", "displayName": "Pretty Print", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "To enable pretty printing output nicely formatted. Is by default false." }, "unmarshalTypeName": { "kind": "attribute", "displayName": "Unmarshal Type Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Class name of the java type to use when unmarshalling" }, - "jsonView": { "kind": "attribute", "displayName": "Json View", "required": false, "type": "string", "javaType": "java.lang.Class<java.lang.Object>", "deprecated": false, "autowired": false, "secret": false, "description": "When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has JsonView annotations" }, + "jsonViewTypeName": { "kind": "attribute", "displayName": "Json View Type Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has JsonView annotations" }, "include": { "kind": "attribute", "displayName": "Include", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "If you want to marshal a pojo to JSON, and the pojo has some fields with null values. And you want to skip these null values, you can set this option to NON_NULL" }, "allowJmsType": { "kind": "attribute", "displayName": "Allow Jms Type", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Used for JMS users to allow the JMSType header from the JMS spec to specify a FQN classname to use to unmarshal to." }, "collectionTypeName": { "kind": "attribute", "displayName": "Collection Type Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Refers to a custom collection type to lookup in the registry to use. This option should rarely be used, but allows to use different collection types than java.util.Collection based as default." }, diff --git a/components/camel-jacksonxml/src/main/docs/jacksonxml-dataformat.adoc b/components/camel-jacksonxml/src/main/docs/jacksonxml-dataformat.adoc index 99345f4..0e3f5e0 100644 --- a/components/camel-jacksonxml/src/main/docs/jacksonxml-dataformat.adoc +++ b/components/camel-jacksonxml/src/main/docs/jacksonxml-dataformat.adoc @@ -52,7 +52,7 @@ The JacksonXML dataformat supports 15 options, which are listed below. | xmlMapper | | String | Lookup and use the existing XmlMapper with the given id. | prettyPrint | false | Boolean | To enable pretty printing output nicely formatted. Is by default false. | unmarshalTypeName | | String | Class name of the java type to use when unmarshalling -| jsonView | | Class | When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has JsonView annotations +| jsonViewTypeName | | String | When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has JsonView annotations | include | | String | If you want to marshal a pojo to JSON, and the pojo has some fields with null values. And you want to skip these null values, you can set this option to NON_NULL | allowJmsType | false | Boolean | Used for JMS users to allow the JMSType header from the JMS spec to specify a FQN classname to use to unmarshal to. | collectionTypeName | | String | Refers to a custom collection type to lookup in the registry to use. This option should rarely be used, but allows to use different collection types than java.util.Collection based as default. diff --git a/components/camel-jacksonxml/src/main/java/org/apache/camel/component/jacksonxml/JacksonXMLDataFormat.java b/components/camel-jacksonxml/src/main/java/org/apache/camel/component/jacksonxml/JacksonXMLDataFormat.java index 1c5b592..594188e 100644 --- a/components/camel-jacksonxml/src/main/java/org/apache/camel/component/jacksonxml/JacksonXMLDataFormat.java +++ b/components/camel-jacksonxml/src/main/java/org/apache/camel/component/jacksonxml/JacksonXMLDataFormat.java @@ -44,6 +44,7 @@ import org.apache.camel.spi.annotations.Dataformat; import org.apache.camel.support.CamelContextHelper; import org.apache.camel.support.ObjectHelper; import org.apache.camel.support.service.ServiceSupport; +import org.apache.camel.util.CastUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -59,12 +60,14 @@ public class JacksonXMLDataFormat extends ServiceSupport private CamelContext camelContext; private XmlMapper xmlMapper; + private String collectionTypeName; private Class<? extends Collection> collectionType; private List<Module> modules; private String moduleClassNames; private String moduleRefs; private String unmarshalTypeName; private Class<?> unmarshalType; + private String jsonViewTypeName; private Class<?> jsonView; private String include; private boolean prettyPrint; @@ -217,6 +220,14 @@ public class JacksonXMLDataFormat extends ServiceSupport this.unmarshalType = unmarshalType; } + public String getCollectionTypeName() { + return collectionTypeName; + } + + public void setCollectionTypeName(String collectionTypeName) { + this.collectionTypeName = collectionTypeName; + } + public Class<? extends Collection> getCollectionType() { return collectionType; } @@ -225,6 +236,14 @@ public class JacksonXMLDataFormat extends ServiceSupport this.collectionType = collectionType; } + public String getJsonViewTypeName() { + return jsonViewTypeName; + } + + public void setJsonViewTypeName(String jsonViewTypeName) { + this.jsonViewTypeName = jsonViewTypeName; + } + public Class<?> getJsonView() { return jsonView; } @@ -466,6 +485,13 @@ public class JacksonXMLDataFormat extends ServiceSupport if (unmarshalTypeName != null && (unmarshalType == null || unmarshalType == HashMap.class)) { unmarshalType = camelContext.getClassResolver().resolveClass(unmarshalTypeName); } + if (jsonViewTypeName != null && jsonView == null) { + jsonView = camelContext.getClassResolver().resolveClass(jsonViewTypeName); + } + if (collectionTypeName != null && collectionType == null) { + Class<?> clazz = camelContext.getClassResolver().resolveClass(collectionTypeName); + collectionType = CastUtils.cast(clazz); + } } @Override diff --git a/components/camel-jacksonxml/src/test/resources/org/apache/camel/component/jacksonxml/SpringJacksonJsonDataFormatTest.xml b/components/camel-jacksonxml/src/test/resources/org/apache/camel/component/jacksonxml/SpringJacksonJsonDataFormatTest.xml index 76d6296..e9e0d5c 100644 --- a/components/camel-jacksonxml/src/test/resources/org/apache/camel/component/jacksonxml/SpringJacksonJsonDataFormatTest.xml +++ b/components/camel-jacksonxml/src/test/resources/org/apache/camel/component/jacksonxml/SpringJacksonJsonDataFormatTest.xml @@ -35,7 +35,7 @@ <!-- and this one uses our own TestPojo class as unmarshal type --> <jacksonxml id="pojo" unmarshalTypeName="org.apache.camel.component.jacksonxml.TestPojo"/> <!-- in addition to our own TestPojoView class we make use of the jsonView attribute here as filter --> - <jacksonxml id="view" unmarshalTypeName="org.apache.camel.component.jacksonxml.TestPojoView" jsonView="org.apache.camel.component.jackson.Views$Age"/> + <jacksonxml id="view" unmarshalTypeName="org.apache.camel.component.jacksonxml.TestPojoView" jsonViewTypeName="org.apache.camel.component.jackson.Views$Age"/> </dataFormats> <route> diff --git a/components/camel-snakeyaml/src/generated/java/org/apache/camel/component/snakeyaml/SnakeYAMLDataFormatConfigurer.java b/components/camel-snakeyaml/src/generated/java/org/apache/camel/component/snakeyaml/SnakeYAMLDataFormatConfigurer.java index 026f700..b30cc30 100644 --- a/components/camel-snakeyaml/src/generated/java/org/apache/camel/component/snakeyaml/SnakeYAMLDataFormatConfigurer.java +++ b/components/camel-snakeyaml/src/generated/java/org/apache/camel/component/snakeyaml/SnakeYAMLDataFormatConfigurer.java @@ -23,6 +23,8 @@ public class SnakeYAMLDataFormatConfigurer extends PropertyConfigurerSupport imp case "dumperoptions": case "dumperOptions": dataformat.setDumperOptions(property(camelContext, java.util.function.Function.class, value)); return true; case "resolver": dataformat.setResolver(property(camelContext, java.util.function.Function.class, value)); return true; + case "unmarshaltypename": + case "unmarshalTypeName": dataformat.setUnmarshalTypeName(property(camelContext, java.lang.String.class, value)); return true; case "useapplicationcontextclassloader": case "useApplicationContextClassLoader": dataformat.setUseApplicationContextClassLoader(property(camelContext, boolean.class, value)); return true; case "prettyflow": diff --git a/components/camel-snakeyaml/src/main/java/org/apache/camel/component/snakeyaml/SnakeYAMLDataFormat.java b/components/camel-snakeyaml/src/main/java/org/apache/camel/component/snakeyaml/SnakeYAMLDataFormat.java index b7aa5fb..6b9fa25 100644 --- a/components/camel-snakeyaml/src/main/java/org/apache/camel/component/snakeyaml/SnakeYAMLDataFormat.java +++ b/components/camel-snakeyaml/src/main/java/org/apache/camel/component/snakeyaml/SnakeYAMLDataFormat.java @@ -32,6 +32,7 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.Function; import org.apache.camel.CamelContext; +import org.apache.camel.CamelContextAware; import org.apache.camel.Exchange; import org.apache.camel.component.snakeyaml.custom.CustomClassLoaderConstructor; import org.apache.camel.spi.DataFormat; @@ -54,13 +55,16 @@ import org.yaml.snakeyaml.resolver.Resolver; * Marshal and unmarshal Java objects to and from YAML using <a href="http://www.snakeyaml.org">SnakeYAML</a> */ @Dataformat("yaml-snakeyaml") -public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFormat, DataFormatName { +public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFormat, DataFormatName, CamelContextAware { + + private CamelContext camelContext; private final ThreadLocal<WeakReference<Yaml>> yamlCache; private Function<CamelContext, BaseConstructor> constructor; private Function<CamelContext, Representer> representer; private Function<CamelContext, DumperOptions> dumperOptions; private Function<CamelContext, Resolver> resolver; private ClassLoader classLoader; + private String unmarshalTypeName; private Class<?> unmarshalType; private List<TypeDescription> typeDescriptions; private ConcurrentMap<Class<?>, Tag> classTags; @@ -98,6 +102,16 @@ public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFor } @Override + public CamelContext getCamelContext() { + return camelContext; + } + + @Override + public void setCamelContext(CamelContext camelContext) { + this.camelContext = camelContext; + } + + @Override public void marshal(final Exchange exchange, final Object graph, final OutputStream stream) throws Exception { try (OutputStreamWriter osw = new OutputStreamWriter(stream, ExchangeHelper.getCharsetName(exchange))) { getYaml(exchange.getContext()).dump(graph, osw); @@ -113,13 +127,12 @@ public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFor } @Override - protected void doStart() throws Exception { - // noop - } + protected void doInit() throws Exception { + super.doInit(); - @Override - protected void doStop() throws Exception { - // noop + if (unmarshalTypeName != null && (unmarshalType == null)) { + setUnmarshalType(camelContext.getClassResolver().resolveClass(unmarshalTypeName)); + } } protected Yaml getYaml(CamelContext context) { @@ -203,6 +216,14 @@ public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFor this.classLoader = classLoader; } + public String getUnmarshalTypeName() { + return unmarshalTypeName; + } + + public void setUnmarshalTypeName(String unmarshalTypeName) { + this.unmarshalTypeName = unmarshalTypeName; + } + public Class<?> getUnmarshalType() { return this.unmarshalType; } diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/dataformat/jacksonxml.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/dataformat/jacksonxml.json index 7475625..acb9edf 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/dataformat/jacksonxml.json +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/dataformat/jacksonxml.json @@ -15,7 +15,7 @@ "xmlMapper": { "kind": "attribute", "displayName": "Xml Mapper", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Lookup and use the existing XmlMapper with the given id." }, "prettyPrint": { "kind": "attribute", "displayName": "Pretty Print", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "To enable pretty printing output nicely formatted. Is by default false." }, "unmarshalTypeName": { "kind": "attribute", "displayName": "Unmarshal Type Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Class name of the java type to use when unmarshalling" }, - "jsonView": { "kind": "attribute", "displayName": "Json View", "required": false, "type": "string", "javaType": "java.lang.Class<java.lang.Object>", "deprecated": false, "autowired": false, "secret": false, "description": "When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has JsonView annotations" }, + "jsonViewTypeName": { "kind": "attribute", "displayName": "Json View Type Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has JsonView annotations" }, "include": { "kind": "attribute", "displayName": "Include", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "If you want to marshal a pojo to JSON, and the pojo has some fields with null values. And you want to skip these null values, you can set this option to NON_NULL" }, "allowJmsType": { "kind": "attribute", "displayName": "Allow Jms Type", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Used for JMS users to allow the JMSType header from the JMS spec to specify a FQN classname to use to unmarshal to." }, "collectionTypeName": { "kind": "attribute", "displayName": "Collection Type Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Refers to a custom collection type to lookup in the registry to use. This option should rarely be used, but allows to use different collection types than java.util.Collection based as default." }, diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/dataformat/json.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/dataformat/json.json index d30b320..f32d4c2 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/dataformat/json.json +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/dataformat/json.json @@ -16,7 +16,7 @@ "prettyPrint": { "kind": "attribute", "displayName": "Pretty Print", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "To enable pretty printing output nicely formatted. Is by default false." }, "library": { "kind": "attribute", "displayName": "Library", "required": false, "type": "enum", "javaType": "org.apache.camel.model.dataformat.JsonLibrary", "enum": [ "fastjson", "gson", "jackson", "johnzon", "jsonb", "x-stream" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "Jackson", "description": "Which json library to use." }, "unmarshalTypeName": { "kind": "attribute", "displayName": "Unmarshal Type Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Class name of the java type to use when unmarshalling" }, - "jsonView": { "kind": "attribute", "displayName": "Json View", "required": false, "type": "string", "javaType": "java.lang.Class<java.lang.Object>", "deprecated": false, "autowired": false, "secret": false, "description": "When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has JsonView annotations" }, + "jsonViewTypeName": { "kind": "attribute", "displayName": "Json View Type Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has JsonView annotations" }, "include": { "kind": "attribute", "displayName": "Include", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "If you want to marshal a pojo to JSON, and the pojo has some fields with null values. And you want to skip these null values, you can set this option to NON_NULL" }, "allowJmsType": { "kind": "attribute", "displayName": "Allow Jms Type", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Used for JMS users to allow the JMSType header from the JMS spec to specify a FQN classname to use to unmarshal to." }, "collectionTypeName": { "kind": "attribute", "displayName": "Collection Type Name", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Refers to a custom collection type to lookup in the registry to use. This option should rarely be used, but allows to use different collection types than java.util.Collection based as default." }, diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/JacksonXMLDataFormat.java b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/JacksonXMLDataFormat.java index 2c4bc93..a0b19fc 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/JacksonXMLDataFormat.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/JacksonXMLDataFormat.java @@ -42,6 +42,8 @@ public class JacksonXMLDataFormat extends DataFormatDefinition implements Conten @XmlTransient private Class<?> unmarshalType; @XmlAttribute + private String jsonViewTypeName; + @XmlTransient private Class<?> jsonView; @XmlAttribute private String include; @@ -125,6 +127,18 @@ public class JacksonXMLDataFormat extends DataFormatDefinition implements Conten this.unmarshalType = unmarshalType; } + public String getJsonViewTypeName() { + return jsonViewTypeName; + } + + /** + * When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you + * can use JSON views to accomplish this. This option is to refer to the class which has @JsonView annotations + */ + public void setJsonViewTypeName(String jsonViewTypeName) { + this.jsonViewTypeName = jsonViewTypeName; + } + public Class<?> getJsonView() { return jsonView; } diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/JsonDataFormat.java b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/JsonDataFormat.java index d9710ec..810815d 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/JsonDataFormat.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/JsonDataFormat.java @@ -50,6 +50,8 @@ public class JsonDataFormat extends DataFormatDefinition implements ContentTypeH @XmlTransient private Class<?> unmarshalType; @XmlAttribute + private String jsonViewTypeName; + @XmlTransient private Class<?> jsonView; @XmlAttribute private String include; @@ -174,6 +176,18 @@ public class JsonDataFormat extends DataFormatDefinition implements ContentTypeH this.library = library; } + public String getJsonViewTypeName() { + return jsonViewTypeName; + } + + /** + * When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you + * can use JSON views to accomplish this. This option is to refer to the class which has @JsonView annotations + */ + public void setJsonViewTypeName(String jsonViewTypeName) { + this.jsonViewTypeName = jsonViewTypeName; + } + public Class<?> getJsonView() { return jsonView; } diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/CBORDataFormatReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/CBORDataFormatReifier.java index 095b938..2371eb7 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/CBORDataFormatReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/CBORDataFormatReifier.java @@ -32,8 +32,16 @@ public class CBORDataFormatReifier extends DataFormatReifier<CBORDataFormat> { protected void prepareDataFormatConfig(Map<String, Object> properties) { // must be a reference value properties.put("xmlMapper", asRef(definition.getObjectMapper())); - properties.put("unmarshalType", or(definition.getUnmarshalType(), definition.getUnmarshalTypeName())); - properties.put("collectionType", or(definition.getCollectionType(), definition.getCollectionTypeName())); + if (definition.getUnmarshalType() != null) { + properties.put("unmarshalTypeName", asTypeName(definition.getUnmarshalType())); + } else { + properties.put("unmarshalTypeName", definition.getUnmarshalTypeName()); + } + if (definition.getCollectionType() != null) { + properties.put("collectionTypeName", asTypeName(definition.getCollectionType())); + } else { + properties.put("collectionTypeName", definition.getCollectionTypeName()); + } properties.put("useList", definition.getUseList()); properties.put("allowUnmarshallType", definition.getAllowUnmarshallType()); properties.put("prettyPrint", definition.getPrettyPrint()); diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/JacksonXMLDataFormatReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/JacksonXMLDataFormatReifier.java index 83674f4..2888865 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/JacksonXMLDataFormatReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/JacksonXMLDataFormatReifier.java @@ -36,8 +36,12 @@ public class JacksonXMLDataFormatReifier extends DataFormatReifier<JacksonXMLDat } else { properties.put("unmarshalTypeName", definition.getUnmarshalTypeName()); } + if (definition.getJsonView() != null) { + properties.put("jsonViewTypeName", asTypeName(definition.getJsonView())); + } else { + properties.put("jsonViewTypeName", definition.getJsonViewTypeName()); + } properties.put("prettyPrint", definition.getPrettyPrint()); - properties.put("jsonView", definition.getJsonView()); properties.put("include", definition.getInclude()); properties.put("allowJmsType", definition.getAllowJmsType()); properties.put("collectionType", or(definition.getCollectionType(), definition.getCollectionTypeName())); diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/JsonDataFormatReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/JsonDataFormatReifier.java index fa4bfa2..f9ca5b3 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/JsonDataFormatReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/JsonDataFormatReifier.java @@ -40,6 +40,11 @@ public class JsonDataFormatReifier extends DataFormatReifier<JsonDataFormat> { properties.put("useDefaultObjectMapper", definition.getUseDefaultObjectMapper()); } properties.put("autoDiscoverObjectMapper", definition.getAutoDiscoverObjectMapper()); + if (definition.getJsonView() != null) { + properties.put("jsonViewTypeName", asTypeName(definition.getJsonView())); + } else { + properties.put("jsonViewTypeName", definition.getJsonViewTypeName()); + } } if (definition.getLibrary() != JsonLibrary.XStream) { if (definition.getUnmarshalType() != null) { @@ -54,7 +59,7 @@ public class JsonDataFormatReifier extends DataFormatReifier<JsonDataFormat> { properties.put("allowJmsType", definition.getAllowJmsType()); if (definition.getLibrary() != JsonLibrary.XStream) { if (definition.getCollectionType() != null) { - properties.put("collectionTypeName", definition.getCollectionType().getName()); + properties.put("collectionTypeName", asTypeName(definition.getCollectionType())); } else { properties.put("collectionTypeName", definition.getCollectionTypeName()); } diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/YAMLDataFormatReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/YAMLDataFormatReifier.java index f1ba7cc..c455990 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/YAMLDataFormatReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/YAMLDataFormatReifier.java @@ -41,7 +41,11 @@ public class YAMLDataFormatReifier extends DataFormatReifier<YAMLDataFormat> { } protected void configureSnakeDataFormat(Map<String, Object> properties) { - properties.put("unmarshalType", or(definition.getUnmarshalType(), definition.getUnmarshalTypeName())); + if (definition.getUnmarshalType() != null) { + properties.put("unmarshalTypeName", asTypeName(definition.getUnmarshalType())); + } else { + properties.put("unmarshalTypeName", definition.getUnmarshalTypeName()); + } properties.put("classLoader", definition.getClassLoader()); properties.put("useApplicationContextClassLoader", definition.getUseApplicationContextClassLoader()); properties.put("prettyFlow", definition.getPrettyFlow()); @@ -60,7 +64,6 @@ public class YAMLDataFormatReifier extends DataFormatReifier<YAMLDataFormat> { List<String> typeFilterDefinitions = new ArrayList<>(definition.getTypeFilters().size()); for (YAMLTypeFilterDefinition definition : definition.getTypeFilters()) { String value = parseString(definition.getValue()); - if (!value.startsWith("type") && !value.startsWith("regexp")) { YAMLTypeFilterType type = parse(YAMLTypeFilterType.class, definition.getType()); if (type == null) { @@ -69,7 +72,6 @@ public class YAMLDataFormatReifier extends DataFormatReifier<YAMLDataFormat> { value = type.name() + ":" + value; } - typeFilterDefinitions.add(value); } return typeFilterDefinitions; 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 a8d7bf6..6bf3418 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 @@ -1962,7 +1962,7 @@ public class ModelParser extends BaseParser { case "enableFeatures": def.setEnableFeatures(val); break; case "enableJaxbAnnotationModule": def.setEnableJaxbAnnotationModule(val); break; case "include": def.setInclude(val); break; - case "jsonView": def.setJsonView(asClass(val)); break; + case "jsonViewTypeName": def.setJsonViewTypeName(val); break; case "moduleClassNames": def.setModuleClassNames(val); break; case "moduleRefs": def.setModuleRefs(val); break; case "prettyPrint": def.setPrettyPrint(val); break; @@ -2023,7 +2023,7 @@ public class ModelParser extends BaseParser { case "dropRootNode": def.setDropRootNode(val); break; case "enableFeatures": def.setEnableFeatures(val); break; case "include": def.setInclude(val); break; - case "jsonView": def.setJsonView(asClass(val)); break; + case "jsonViewTypeName": def.setJsonViewTypeName(val); break; case "library": def.setLibrary(JsonLibrary.valueOf(val)); break; case "moduleClassNames": def.setModuleClassNames(val); break; case "moduleRefs": def.setModuleRefs(val); break; diff --git a/docs/components/modules/dataformats/pages/jacksonxml-dataformat.adoc b/docs/components/modules/dataformats/pages/jacksonxml-dataformat.adoc index 461dfdb..3b4d3fc 100644 --- a/docs/components/modules/dataformats/pages/jacksonxml-dataformat.adoc +++ b/docs/components/modules/dataformats/pages/jacksonxml-dataformat.adoc @@ -54,7 +54,7 @@ The JacksonXML dataformat supports 15 options, which are listed below. | xmlMapper | | String | Lookup and use the existing XmlMapper with the given id. | prettyPrint | false | Boolean | To enable pretty printing output nicely formatted. Is by default false. | unmarshalTypeName | | String | Class name of the java type to use when unmarshalling -| jsonView | | Class | When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has JsonView annotations +| jsonViewTypeName | | String | When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has JsonView annotations | include | | String | If you want to marshal a pojo to JSON, and the pojo has some fields with null values. And you want to skip these null values, you can set this option to NON_NULL | allowJmsType | false | Boolean | Used for JMS users to allow the JMSType header from the JMS spec to specify a FQN classname to use to unmarshal to. | collectionTypeName | | String | Refers to a custom collection type to lookup in the registry to use. This option should rarely be used, but allows to use different collection types than java.util.Collection based as default. diff --git a/docs/components/modules/dataformats/pages/json-jackson-dataformat.adoc b/docs/components/modules/dataformats/pages/json-jackson-dataformat.adoc index 617422f..b246139 100644 --- a/docs/components/modules/dataformats/pages/json-jackson-dataformat.adoc +++ b/docs/components/modules/dataformats/pages/json-jackson-dataformat.adoc @@ -37,7 +37,7 @@ The JSON Jackson dataformat supports 17 options, which are listed below. | useDefaultObjectMapper | true | Boolean | Whether to lookup and use default Jackson ObjectMapper from the registry. | prettyPrint | false | Boolean | To enable pretty printing output nicely formatted. Is by default false. | unmarshalTypeName | | String | Class name of the java type to use when unmarshalling -| jsonView | | Class | When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has JsonView annotations +| jsonViewTypeName | | String | When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. This option is to refer to the class which has JsonView annotations | include | | String | If you want to marshal a pojo to JSON, and the pojo has some fields with null values. And you want to skip these null values, you can set this option to NON_NULL | allowJmsType | false | Boolean | Used for JMS users to allow the JMSType header from the JMS spec to specify a FQN classname to use to unmarshal to. | collectionTypeName | | String | Refers to a custom collection type to lookup in the registry to use. This option should rarely be used, but allows to use different collection types than java.util.Collection based as default. diff --git a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_8.adoc b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_8.adoc index 49d7832..11c67f6 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_8.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_8.adoc @@ -33,6 +33,11 @@ The method `isOnlyDynamicQueryParameters` is removed from `org.apache.camel.spi. The `onCompletion` EIP has fixed it could trigger multiple completions for a given `Exchange` +=== camel-jackson + +When using XML DSL then `jsonView` has been renamed to `jsonViewTypeName` and made general available in the model, +and for the lightweight `camel-xml-io` route parser. + === camel-caffeine-lrucache This LRUCache implementation is using an algorithm where elements that are removed may not be in strict order, and therefore