This is an automated email from the ASF dual-hosted git repository. nferraro pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit f06e1818b5457d5a07f41bea4d2e11d51552f975 Author: nicolaferraro <[email protected]> AuthorDate: Fri May 14 10:18:13 2021 +0200 Add model and reifier for avro-jackson and protobuf-jackson dataformats --- .../camel/component/jackson/avro/avro-jackson.json | 32 +- .../jackson/avro/JacksonAvroDataFormat.java | 2 - .../jackson/protobuf/protobuf-jackson.json | 32 +- .../services/org/apache/camel/model.properties | 2 + .../camel/model/dataformat/avro-jackson.json | 34 ++ .../org/apache/camel/model/dataformat/jaxb.index | 2 + .../camel/model/dataformat/protobuf-jackson.json | 34 ++ .../org/apache/camel/builder/DataFormatClause.java | 34 ++ .../model/dataformat/AvroJacksonDataFormat.java | 452 +++++++++++++++++++++ .../dataformat/ProtobufJacksonDataFormat.java | 452 +++++++++++++++++++++ .../dataformat/AvroJacksonDataFormatReifier.java | 68 ++++ .../reifier/dataformat/DataFormatReifier.java | 6 + .../ProtobufJacksonDataFormatReifier.java | 68 ++++ 13 files changed, 1200 insertions(+), 18 deletions(-) diff --git a/components/camel-jackson-avro/src/generated/resources/org/apache/camel/component/jackson/avro/avro-jackson.json b/components/camel-jackson-avro/src/generated/resources/org/apache/camel/component/jackson/avro/avro-jackson.json index 4826f7f..09954c2 100644 --- a/components/camel-jackson-avro/src/generated/resources/org/apache/camel/component/jackson/avro/avro-jackson.json +++ b/components/camel-jackson-avro/src/generated/resources/org/apache/camel/component/jackson/avro/avro-jackson.json @@ -2,21 +2,37 @@ "dataformat": { "kind": "dataformat", "name": "avro-jackson", - "title": "Avro", - "description": "Serialize and deserialize messages using Apache Avro binary data format.", + "title": "Avro Jackson", + "description": "Marshal POJOs to JSON and back.", "deprecated": false, - "firstVersion": "2.14.0", - "label": "dataformat,transformation", + "firstVersion": "3.10.0", + "label": "dataformat,transformation,json", "javaType": "org.apache.camel.component.jackson.avro.JacksonAvroDataFormat", - "supportLevel": "Stable", + "supportLevel": "Preview", "groupId": "org.apache.camel", "artifactId": "camel-jackson-avro", "version": "3.10.0-SNAPSHOT", - "modelName": "avro", - "modelJavaType": "org.apache.camel.model.dataformat.AvroDataFormat" + "modelName": "avro-jackson", + "modelJavaType": "org.apache.camel.model.dataformat.AvroJacksonDataFormat" }, "properties": { - "instanceClassName": { "kind": "attribute", "displayName": "Instance Class Name", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Class name to use for marshal and unmarshalling" }, + "objectMapper": { "kind": "attribute", "displayName": "Object Mapper", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Lookup and use the existing ObjectMapper with the given id when using Jackson." }, + "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" }, + "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." }, + "useList": { "kind": "attribute", "displayName": "Use List", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "To unmarshal to a List of Map or a List of Pojo." }, + "moduleClassNames": { "kind": "attribute", "displayName": "Module Class Names", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To use custom Jackson modules com.fasterxml.jackson.databind.Module specified as a String with FQN class names. Multiple classes can be separated by comma." }, + "moduleRefs": { "kind": "attribute", "displayName": "Module Refs", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To use custom Jackson modules referred from the Camel registry. Multiple modules can be separated by comma." }, + "enableFeatures": { "kind": "attribute", "displayName": "Enable Features", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Set of features to enable on the Jackson com.fasterxml.jackson.databind.ObjectMapper. The features should be a name that matches a enum from com.fasterxml.jackson.databind.SerializationFeature, com.fasterxml.jackson.databind.DeserializationFeature, or com.fasterxml.jack [...] + "disableFeatures": { "kind": "attribute", "displayName": "Disable Features", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Set of features to disable on the Jackson com.fasterxml.jackson.databind.ObjectMapper. The features should be a name that matches a enum from com.fasterxml.jackson.databind.SerializationFeature, com.fasterxml.jackson.databind.DeserializationFeature, or com.fasterxml.j [...] + "allowUnmarshallType": { "kind": "attribute", "displayName": "Allow Unmarshall Type", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "If enabled then Jackson is allowed to attempt to use the CamelJacksonUnmarshalType header during the unmarshalling. This should only be enabled when desired to be used." }, + "timezone": { "kind": "attribute", "displayName": "Timezone", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "If set then Jackson will use the Timezone when marshalling\/unmarshalling." }, + "autoDiscoverObjectMapper": { "kind": "attribute", "displayName": "Auto Discover Object Mapper", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "If set to true then Jackson will lookup for an objectMapper into the registry" }, + "contentTypeHeader": { "kind": "attribute", "displayName": "Content Type Header", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether the data format should set the Content-Type header with the type from the data format. For example application\/xml for data formats marshalling to XML, or application\/json for data formats marshalling to JSON" }, "id": { "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The id of this node" } } } diff --git a/components/camel-jackson-avro/src/main/java/org/apache/camel/component/jackson/avro/JacksonAvroDataFormat.java b/components/camel-jackson-avro/src/main/java/org/apache/camel/component/jackson/avro/JacksonAvroDataFormat.java index 3ee8bb1..6c1e568 100644 --- a/components/camel-jackson-avro/src/main/java/org/apache/camel/component/jackson/avro/JacksonAvroDataFormat.java +++ b/components/camel-jackson-avro/src/main/java/org/apache/camel/component/jackson/avro/JacksonAvroDataFormat.java @@ -75,8 +75,6 @@ public class JacksonAvroDataFormat extends AbstractJacksonDataFormat { super(mapper, unmarshalType, jsonView); } - - @Override public String getDataFormatName() { return "avro-jackson"; diff --git a/components/camel-jackson-protobuf/src/generated/resources/org/apache/camel/component/jackson/protobuf/protobuf-jackson.json b/components/camel-jackson-protobuf/src/generated/resources/org/apache/camel/component/jackson/protobuf/protobuf-jackson.json index 7da3c24..b7c9474 100644 --- a/components/camel-jackson-protobuf/src/generated/resources/org/apache/camel/component/jackson/protobuf/protobuf-jackson.json +++ b/components/camel-jackson-protobuf/src/generated/resources/org/apache/camel/component/jackson/protobuf/protobuf-jackson.json @@ -2,21 +2,37 @@ "dataformat": { "kind": "dataformat", "name": "protobuf-jackson", - "title": "Avro", - "description": "Serialize and deserialize messages using Apache Avro binary data format.", + "title": "Protobuf Jackson", + "description": "Marshal POJOs to JSON and back.", "deprecated": false, - "firstVersion": "2.14.0", - "label": "dataformat,transformation", + "firstVersion": "3.10.0", + "label": "dataformat,transformation,json", "javaType": "org.apache.camel.component.jackson.protobuf.JacksonProtobufDataFormat", - "supportLevel": "Stable", + "supportLevel": "Preview", "groupId": "org.apache.camel", "artifactId": "camel-jackson-protobuf", "version": "3.10.0-SNAPSHOT", - "modelName": "avro", - "modelJavaType": "org.apache.camel.model.dataformat.AvroDataFormat" + "modelName": "protobuf-jackson", + "modelJavaType": "org.apache.camel.model.dataformat.ProtobufJacksonDataFormat" }, "properties": { - "instanceClassName": { "kind": "attribute", "displayName": "Instance Class Name", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Class name to use for marshal and unmarshalling" }, + "objectMapper": { "kind": "attribute", "displayName": "Object Mapper", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Lookup and use the existing ObjectMapper with the given id when using Jackson." }, + "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" }, + "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." }, + "useList": { "kind": "attribute", "displayName": "Use List", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "To unmarshal to a List of Map or a List of Pojo." }, + "moduleClassNames": { "kind": "attribute", "displayName": "Module Class Names", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To use custom Jackson modules com.fasterxml.jackson.databind.Module specified as a String with FQN class names. Multiple classes can be separated by comma." }, + "moduleRefs": { "kind": "attribute", "displayName": "Module Refs", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To use custom Jackson modules referred from the Camel registry. Multiple modules can be separated by comma." }, + "enableFeatures": { "kind": "attribute", "displayName": "Enable Features", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Set of features to enable on the Jackson com.fasterxml.jackson.databind.ObjectMapper. The features should be a name that matches a enum from com.fasterxml.jackson.databind.SerializationFeature, com.fasterxml.jackson.databind.DeserializationFeature, or com.fasterxml.jack [...] + "disableFeatures": { "kind": "attribute", "displayName": "Disable Features", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Set of features to disable on the Jackson com.fasterxml.jackson.databind.ObjectMapper. The features should be a name that matches a enum from com.fasterxml.jackson.databind.SerializationFeature, com.fasterxml.jackson.databind.DeserializationFeature, or com.fasterxml.j [...] + "allowUnmarshallType": { "kind": "attribute", "displayName": "Allow Unmarshall Type", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "If enabled then Jackson is allowed to attempt to use the CamelJacksonUnmarshalType header during the unmarshalling. This should only be enabled when desired to be used." }, + "timezone": { "kind": "attribute", "displayName": "Timezone", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "If set then Jackson will use the Timezone when marshalling\/unmarshalling." }, + "autoDiscoverObjectMapper": { "kind": "attribute", "displayName": "Auto Discover Object Mapper", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "If set to true then Jackson will lookup for an objectMapper into the registry" }, + "contentTypeHeader": { "kind": "attribute", "displayName": "Content Type Header", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether the data format should set the Content-Type header with the type from the data format. For example application\/xml for data formats marshalling to XML, or application\/json for data formats marshalling to JSON" }, "id": { "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The id of this node" } } } diff --git a/core/camel-core-model/src/generated/resources/META-INF/services/org/apache/camel/model.properties b/core/camel-core-model/src/generated/resources/META-INF/services/org/apache/camel/model.properties index 19029a3..6ccf802 100644 --- a/core/camel-core-model/src/generated/resources/META-INF/services/org/apache/camel/model.properties +++ b/core/camel-core-model/src/generated/resources/META-INF/services/org/apache/camel/model.properties @@ -4,6 +4,7 @@ any23 apiKey asn1 avro +avro-jackson barcode base64 basicAuth @@ -110,6 +111,7 @@ post process property protobuf +protobuf-jackson put random recipientList diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/dataformat/avro-jackson.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/dataformat/avro-jackson.json new file mode 100644 index 0000000..a2067b2 --- /dev/null +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/dataformat/avro-jackson.json @@ -0,0 +1,34 @@ +{ + "model": { + "kind": "model", + "name": "avro-jackson", + "title": "Avro Jackson", + "description": "Marshal POJOs to Avro using Jackson and back.", + "deprecated": false, + "firstVersion": "3.10.0", + "label": "dataformat,transformation,json", + "javaType": "org.apache.camel.model.dataformat.AvroJacksonDataFormat", + "input": false, + "output": false + }, + "properties": { + "objectMapper": { "kind": "attribute", "displayName": "Object Mapper", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Lookup and use the existing ObjectMapper with the given id when using Jackson." }, + "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" }, + "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." }, + "useList": { "kind": "attribute", "displayName": "Use List", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "To unmarshal to a List of Map or a List of Pojo." }, + "moduleClassNames": { "kind": "attribute", "displayName": "Module Class Names", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To use custom Jackson modules com.fasterxml.jackson.databind.Module specified as a String with FQN class names. Multiple classes can be separated by comma." }, + "moduleRefs": { "kind": "attribute", "displayName": "Module Refs", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To use custom Jackson modules referred from the Camel registry. Multiple modules can be separated by comma." }, + "enableFeatures": { "kind": "attribute", "displayName": "Enable Features", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Set of features to enable on the Jackson com.fasterxml.jackson.databind.ObjectMapper. The features should be a name that matches a enum from com.fasterxml.jackson.databind.SerializationFeature, com.fasterxml.jackson.databind.DeserializationFeature, or com.fasterxml.jack [...] + "disableFeatures": { "kind": "attribute", "displayName": "Disable Features", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Set of features to disable on the Jackson com.fasterxml.jackson.databind.ObjectMapper. The features should be a name that matches a enum from com.fasterxml.jackson.databind.SerializationFeature, com.fasterxml.jackson.databind.DeserializationFeature, or com.fasterxml.j [...] + "allowUnmarshallType": { "kind": "attribute", "displayName": "Allow Unmarshall Type", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "If enabled then Jackson is allowed to attempt to use the CamelJacksonUnmarshalType header during the unmarshalling. This should only be enabled when desired to be used." }, + "timezone": { "kind": "attribute", "displayName": "Timezone", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "If set then Jackson will use the Timezone when marshalling\/unmarshalling." }, + "autoDiscoverObjectMapper": { "kind": "attribute", "displayName": "Auto Discover Object Mapper", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "If set to true then Jackson will lookup for an objectMapper into the registry" }, + "contentTypeHeader": { "kind": "attribute", "displayName": "Content Type Header", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether the data format should set the Content-Type header with the type from the data format. For example application\/xml for data formats marshalling to XML, or application\/json for data formats marshalling to JSON" }, + "id": { "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The id of this node" } + } +} diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/dataformat/jaxb.index b/core/camel-core-model/src/generated/resources/org/apache/camel/model/dataformat/jaxb.index index 3c81a9c..b1e7635 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/dataformat/jaxb.index +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/dataformat/jaxb.index @@ -3,6 +3,7 @@ ASN1DataFormat Any23DataFormat Any23Type AvroDataFormat +AvroJacksonDataFormat BarcodeDataFormat Base64DataFormat BeanioDataFormat @@ -29,6 +30,7 @@ LZFDataFormat MimeMultipartDataFormat PGPDataFormat ProtobufDataFormat +ProtobufJacksonDataFormat RssDataFormat SoapJaxbDataFormat SyslogDataFormat diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/dataformat/protobuf-jackson.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/dataformat/protobuf-jackson.json new file mode 100644 index 0000000..9c67909 --- /dev/null +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/dataformat/protobuf-jackson.json @@ -0,0 +1,34 @@ +{ + "model": { + "kind": "model", + "name": "protobuf-jackson", + "title": "Protobuf Jackson", + "description": "Marshal POJOs to Protobuf using Jackson and back.", + "deprecated": false, + "firstVersion": "3.10.0", + "label": "dataformat,transformation,json", + "javaType": "org.apache.camel.model.dataformat.ProtobufJacksonDataFormat", + "input": false, + "output": false + }, + "properties": { + "objectMapper": { "kind": "attribute", "displayName": "Object Mapper", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Lookup and use the existing ObjectMapper with the given id when using Jackson." }, + "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" }, + "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." }, + "useList": { "kind": "attribute", "displayName": "Use List", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "To unmarshal to a List of Map or a List of Pojo." }, + "moduleClassNames": { "kind": "attribute", "displayName": "Module Class Names", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To use custom Jackson modules com.fasterxml.jackson.databind.Module specified as a String with FQN class names. Multiple classes can be separated by comma." }, + "moduleRefs": { "kind": "attribute", "displayName": "Module Refs", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "To use custom Jackson modules referred from the Camel registry. Multiple modules can be separated by comma." }, + "enableFeatures": { "kind": "attribute", "displayName": "Enable Features", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Set of features to enable on the Jackson com.fasterxml.jackson.databind.ObjectMapper. The features should be a name that matches a enum from com.fasterxml.jackson.databind.SerializationFeature, com.fasterxml.jackson.databind.DeserializationFeature, or com.fasterxml.jack [...] + "disableFeatures": { "kind": "attribute", "displayName": "Disable Features", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Set of features to disable on the Jackson com.fasterxml.jackson.databind.ObjectMapper. The features should be a name that matches a enum from com.fasterxml.jackson.databind.SerializationFeature, com.fasterxml.jackson.databind.DeserializationFeature, or com.fasterxml.j [...] + "allowUnmarshallType": { "kind": "attribute", "displayName": "Allow Unmarshall Type", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "If enabled then Jackson is allowed to attempt to use the CamelJacksonUnmarshalType header during the unmarshalling. This should only be enabled when desired to be used." }, + "timezone": { "kind": "attribute", "displayName": "Timezone", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "If set then Jackson will use the Timezone when marshalling\/unmarshalling." }, + "autoDiscoverObjectMapper": { "kind": "attribute", "displayName": "Auto Discover Object Mapper", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "If set to true then Jackson will lookup for an objectMapper into the registry" }, + "contentTypeHeader": { "kind": "attribute", "displayName": "Content Type Header", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether the data format should set the Content-Type header with the type from the data format. For example application\/xml for data formats marshalling to XML, or application\/json for data formats marshalling to JSON" }, + "id": { "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The id of this node" } + } +} diff --git a/core/camel-core-model/src/main/java/org/apache/camel/builder/DataFormatClause.java b/core/camel-core-model/src/main/java/org/apache/camel/builder/DataFormatClause.java index 5713481..cdcc155 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/builder/DataFormatClause.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/builder/DataFormatClause.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; import java.util.StringJoiner; +import org.apache.camel.model.dataformat.ProtobufJacksonDataFormat; import org.w3c.dom.Node; import org.apache.camel.model.DataFormatDefinition; @@ -29,6 +30,7 @@ import org.apache.camel.model.dataformat.ASN1DataFormat; import org.apache.camel.model.dataformat.Any23DataFormat; import org.apache.camel.model.dataformat.Any23Type; import org.apache.camel.model.dataformat.AvroDataFormat; +import org.apache.camel.model.dataformat.AvroJacksonDataFormat; import org.apache.camel.model.dataformat.Base64DataFormat; import org.apache.camel.model.dataformat.BeanioDataFormat; import org.apache.camel.model.dataformat.BindyDataFormat; @@ -535,6 +537,22 @@ public class DataFormatClause<T extends ProcessorDefinition<?>> { } /** + * Uses the Jackson Avro data format + */ + public T avroJackson() { + return dataFormat(new AvroJacksonDataFormat()); + } + + /** + * Uses the Jackson Avro data format with given unmarshalType + */ + public T avroJackson(Class<?> unmarshalType) { + AvroJacksonDataFormat avroJacksonDataFormat = new AvroJacksonDataFormat(); + avroJacksonDataFormat.setUnmarshalType(unmarshalType); + return dataFormat(avroJacksonDataFormat); + } + + /** * Uses the JAXB data format */ public T jaxb() { @@ -729,6 +747,22 @@ public class DataFormatClause<T extends ProcessorDefinition<?>> { } /** + * Uses the Jackson Protobuf data format + */ + public T protobufJackson() { + return dataFormat(new ProtobufDataFormat()); + } + + /** + * Uses the Jackson Protobuf data format with given unmarshalType + */ + public T protobufJackson(Class<?> unmarshalType) { + ProtobufJacksonDataFormat protobufJacksonDataFormat = new ProtobufJacksonDataFormat(); + protobufJacksonDataFormat.setUnmarshalType(unmarshalType); + return dataFormat(protobufJacksonDataFormat); + } + + /** * Uses the RSS data format */ public T rss() { diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/AvroJacksonDataFormat.java b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/AvroJacksonDataFormat.java new file mode 100644 index 0000000..17a1e2a --- /dev/null +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/AvroJacksonDataFormat.java @@ -0,0 +1,452 @@ +/* + * 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.model.dataformat; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; + +import org.apache.camel.model.DataFormatDefinition; +import org.apache.camel.spi.Metadata; + +/** + * Marshal POJOs to Avro using Jackson and back. + */ +@Metadata(firstVersion = "3.10.0", label = "dataformat,transformation,json", title = "Avro Jackson") +@XmlRootElement(name = "avro-jackson") +@XmlAccessorType(XmlAccessType.FIELD) +public class AvroJacksonDataFormat extends DataFormatDefinition implements ContentTypeHeaderAware { + @XmlAttribute + private String objectMapper; + @XmlAttribute + @Metadata(javaType = "java.lang.Boolean", defaultValue = "true") + private String useDefaultObjectMapper; + @XmlAttribute + @Metadata(javaType = "java.lang.Boolean") + private String prettyPrint; + @XmlAttribute + private String unmarshalTypeName; + @XmlTransient + private Class<?> unmarshalType; + @XmlAttribute + private String jsonViewTypeName; + @XmlTransient + private Class<?> jsonView; + @XmlAttribute + private String include; + @XmlAttribute + @Metadata(javaType = "java.lang.Boolean") + private String allowJmsType; + @XmlAttribute + private String collectionTypeName; + @XmlTransient + private Class<?> collectionType; + @XmlAttribute + @Metadata(javaType = "java.lang.Boolean") + private String useList; + @XmlAttribute + private String moduleClassNames; + @XmlAttribute + private String moduleRefs; + @XmlAttribute + private String enableFeatures; + @XmlAttribute + private String disableFeatures; + @XmlAttribute + @Metadata(javaType = "java.lang.Boolean") + private String allowUnmarshallType; + @XmlAttribute + private String timezone; + @XmlAttribute + @Metadata(javaType = "java.lang.Boolean", defaultValue = "false") + private String autoDiscoverObjectMapper; + @XmlAttribute + @Metadata(javaType = "java.lang.Boolean", defaultValue = "true", + description = "Whether the data format should set the Content-Type header with the type from the data format." + + " For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSON") + private String contentTypeHeader; + + public AvroJacksonDataFormat() { + super("avro-jackson"); + } + + public String getContentTypeHeader() { + return contentTypeHeader; + } + + public void setContentTypeHeader(String contentTypeHeader) { + this.contentTypeHeader = contentTypeHeader; + } + + public String getObjectMapper() { + return objectMapper; + } + + /** + * Lookup and use the existing ObjectMapper with the given id when using Jackson. + */ + public void setObjectMapper(String objectMapper) { + this.objectMapper = objectMapper; + } + + public String getUseDefaultObjectMapper() { + return useDefaultObjectMapper; + } + + /** + * Whether to lookup and use default Jackson ObjectMapper from the registry. + */ + public void setUseDefaultObjectMapper(String useDefaultObjectMapper) { + this.useDefaultObjectMapper = useDefaultObjectMapper; + } + + public String getPrettyPrint() { + return prettyPrint; + } + + /** + * To enable pretty printing output nicely formatted. + * <p/> + * Is by default false. + */ + public void setPrettyPrint(String prettyPrint) { + this.prettyPrint = prettyPrint; + } + + public String getUnmarshalTypeName() { + return unmarshalTypeName; + } + + /** + * Class name of the java type to use when unmarshalling + */ + public void setUnmarshalTypeName(String unmarshalTypeName) { + this.unmarshalTypeName = unmarshalTypeName; + } + + public Class<?> getUnmarshalType() { + return unmarshalType; + } + + /** + * Class of the java type to use when unmarshalling + */ + public void setUnmarshalType(Class<?> unmarshalType) { + 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; + } + + /** + * 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 setJsonView(Class<?> jsonView) { + this.jsonView = jsonView; + } + + public String getInclude() { + return include; + } + + /** + * 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 <tt>NON_NULL</tt> + */ + public void setInclude(String include) { + this.include = include; + } + + public String getAllowJmsType() { + return allowJmsType; + } + + /** + * Used for JMS users to allow the JMSType header from the JMS spec to specify a FQN classname to use to unmarshal + * to. + */ + public void setAllowJmsType(String allowJmsType) { + this.allowJmsType = allowJmsType; + } + + public String getCollectionTypeName() { + return collectionTypeName; + } + + /** + * 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. + */ + public void setCollectionTypeName(String collectionTypeName) { + this.collectionTypeName = collectionTypeName; + } + + public Class<?> getCollectionType() { + return collectionType; + } + + public void setCollectionType(Class<?> collectionType) { + this.collectionType = collectionType; + } + + public String getUseList() { + return useList; + } + + /** + * To unmarshal to a List of Map or a List of Pojo. + */ + public void setUseList(String useList) { + this.useList = useList; + } + + public String getModuleClassNames() { + return moduleClassNames; + } + + /** + * To use custom Jackson modules com.fasterxml.jackson.databind.Module specified as a String with FQN class names. + * Multiple classes can be separated by comma. + */ + public void setModuleClassNames(String moduleClassNames) { + this.moduleClassNames = moduleClassNames; + } + + public String getModuleRefs() { + return moduleRefs; + } + + /** + * To use custom Jackson modules referred from the Camel registry. Multiple modules can be separated by comma. + */ + public void setModuleRefs(String moduleRefs) { + this.moduleRefs = moduleRefs; + } + + public String getEnableFeatures() { + return enableFeatures; + } + + /** + * Set of features to enable on the Jackson <tt>com.fasterxml.jackson.databind.ObjectMapper</tt>. + * <p/> + * The features should be a name that matches a enum from + * <tt>com.fasterxml.jackson.databind.SerializationFeature</tt>, + * <tt>com.fasterxml.jackson.databind.DeserializationFeature</tt>, or + * <tt>com.fasterxml.jackson.databind.MapperFeature</tt> + * <p/> + * Multiple features can be separated by comma + */ + public void setEnableFeatures(String enableFeatures) { + this.enableFeatures = enableFeatures; + } + + public String getDisableFeatures() { + return disableFeatures; + } + + /** + * Set of features to disable on the Jackson <tt>com.fasterxml.jackson.databind.ObjectMapper</tt>. + * <p/> + * The features should be a name that matches a enum from + * <tt>com.fasterxml.jackson.databind.SerializationFeature</tt>, + * <tt>com.fasterxml.jackson.databind.DeserializationFeature</tt>, or + * <tt>com.fasterxml.jackson.databind.MapperFeature</tt> + * <p/> + * Multiple features can be separated by comma + */ + public void setDisableFeatures(String disableFeatures) { + this.disableFeatures = disableFeatures; + } + + public String getAllowUnmarshallType() { + return allowUnmarshallType; + } + + /** + * If enabled then Jackson is allowed to attempt to use the CamelJacksonUnmarshalType header during the + * unmarshalling. + * <p/> + * This should only be enabled when desired to be used. + */ + public void setAllowUnmarshallType(String allowUnmarshallType) { + this.allowUnmarshallType = allowUnmarshallType; + } + + public String getTimezone() { + return timezone; + } + + /** + * If set then Jackson will use the Timezone when marshalling/unmarshalling. + */ + public void setTimezone(String timezone) { + this.timezone = timezone; + } + + public String getAutoDiscoverObjectMapper() { + return autoDiscoverObjectMapper; + } + + /** + * If set to true then Jackson will lookup for an objectMapper into the registry + */ + public void setAutoDiscoverObjectMapper(String autoDiscoverObjectMapper) { + this.autoDiscoverObjectMapper = autoDiscoverObjectMapper; + } + + @Override + public String getDataFormatName() { + // json data format is special as the name can be from different bundles + return "avro-jackson"; + } + + // + // Fluent builders + // + + public AvroJacksonDataFormat objectMapper(String objectMapper) { + this.objectMapper = objectMapper; + return this; + } + + public AvroJacksonDataFormat useDefaultObjectMapper(boolean useDefaultObjectMapper) { + return useDefaultObjectMapper(Boolean.toString(useDefaultObjectMapper)); + } + + public AvroJacksonDataFormat useDefaultObjectMapper(String useDefaultObjectMapper) { + this.useDefaultObjectMapper = useDefaultObjectMapper; + return this; + } + + public AvroJacksonDataFormat prettyPrint(boolean prettyPrint) { + return prettyPrint(Boolean.toString(prettyPrint)); + } + + public AvroJacksonDataFormat prettyPrint(String prettyPrint) { + this.prettyPrint = prettyPrint; + return this; + } + + public AvroJacksonDataFormat unmarshalType(String unmarshalType) { + this.unmarshalTypeName = unmarshalType; + return this; + } + + public AvroJacksonDataFormat unmarshalType(Class<?> unmarshalType) { + this.unmarshalType = unmarshalType; + return this; + } + + public AvroJacksonDataFormat jsonView(Class<?> jsonView) { + this.jsonView = jsonView; + return this; + } + + public AvroJacksonDataFormat include(String include) { + this.include = include; + return this; + } + + public AvroJacksonDataFormat allowJmsType(boolean allowJmsType) { + return allowJmsType(Boolean.toString(allowJmsType)); + } + + public AvroJacksonDataFormat allowJmsType(String allowJmsType) { + this.allowJmsType = allowJmsType; + return this; + } + + public AvroJacksonDataFormat collectionType(String collectionType) { + this.collectionTypeName = collectionType; + return this; + } + + public AvroJacksonDataFormat collectionType(Class<?> collectionType) { + this.collectionType = collectionType; + return this; + } + + public AvroJacksonDataFormat useList(boolean useList) { + return useList(Boolean.toString(useList)); + } + + public AvroJacksonDataFormat useList(String useList) { + this.useList = useList; + return this; + } + + public AvroJacksonDataFormat moduleClassNames(String moduleClassNames) { + this.moduleClassNames = moduleClassNames; + return this; + } + + public AvroJacksonDataFormat moduleRefs(String moduleRefs) { + this.moduleRefs = moduleRefs; + return this; + } + + public AvroJacksonDataFormat enableFeatures(String enableFeatures) { + this.enableFeatures = enableFeatures; + return this; + } + + public AvroJacksonDataFormat disableFeatures(String disableFeatures) { + this.disableFeatures = disableFeatures; + return this; + } + + public AvroJacksonDataFormat allowUnmarshallType(boolean allowUnmarshallType) { + return allowUnmarshallType(Boolean.toString(allowUnmarshallType)); + } + + public AvroJacksonDataFormat allowUnmarshallType(String allowUnmarshallType) { + this.allowUnmarshallType = allowUnmarshallType; + return this; + } + + public AvroJacksonDataFormat timezone(String timezone) { + this.timezone = timezone; + return this; + } + + public AvroJacksonDataFormat autoDiscoverObjectMapper(boolean autoDiscoverObjectMapper) { + return autoDiscoverObjectMapper(Boolean.toString(autoDiscoverObjectMapper)); + } + + public AvroJacksonDataFormat autoDiscoverObjectMapper(String autoDiscoverObjectMapper) { + this.autoDiscoverObjectMapper = autoDiscoverObjectMapper; + return this; + } + +} diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/ProtobufJacksonDataFormat.java b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/ProtobufJacksonDataFormat.java new file mode 100644 index 0000000..0aa28c9 --- /dev/null +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/ProtobufJacksonDataFormat.java @@ -0,0 +1,452 @@ +/* + * 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.model.dataformat; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; + +import org.apache.camel.model.DataFormatDefinition; +import org.apache.camel.spi.Metadata; + +/** + * Marshal POJOs to Protobuf using Jackson and back. + */ +@Metadata(firstVersion = "3.10.0", label = "dataformat,transformation,json", title = "Protobuf Jackson") +@XmlRootElement(name = "protobuf-jackson") +@XmlAccessorType(XmlAccessType.FIELD) +public class ProtobufJacksonDataFormat extends DataFormatDefinition implements ContentTypeHeaderAware { + @XmlAttribute + private String objectMapper; + @XmlAttribute + @Metadata(javaType = "java.lang.Boolean", defaultValue = "true") + private String useDefaultObjectMapper; + @XmlAttribute + @Metadata(javaType = "java.lang.Boolean") + private String prettyPrint; + @XmlAttribute + private String unmarshalTypeName; + @XmlTransient + private Class<?> unmarshalType; + @XmlAttribute + private String jsonViewTypeName; + @XmlTransient + private Class<?> jsonView; + @XmlAttribute + private String include; + @XmlAttribute + @Metadata(javaType = "java.lang.Boolean") + private String allowJmsType; + @XmlAttribute + private String collectionTypeName; + @XmlTransient + private Class<?> collectionType; + @XmlAttribute + @Metadata(javaType = "java.lang.Boolean") + private String useList; + @XmlAttribute + private String moduleClassNames; + @XmlAttribute + private String moduleRefs; + @XmlAttribute + private String enableFeatures; + @XmlAttribute + private String disableFeatures; + @XmlAttribute + @Metadata(javaType = "java.lang.Boolean") + private String allowUnmarshallType; + @XmlAttribute + private String timezone; + @XmlAttribute + @Metadata(javaType = "java.lang.Boolean", defaultValue = "false") + private String autoDiscoverObjectMapper; + @XmlAttribute + @Metadata(javaType = "java.lang.Boolean", defaultValue = "true", + description = "Whether the data format should set the Content-Type header with the type from the data format." + + " For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSON") + private String contentTypeHeader; + + public ProtobufJacksonDataFormat() { + super("protobuf-jackson"); + } + + public String getContentTypeHeader() { + return contentTypeHeader; + } + + public void setContentTypeHeader(String contentTypeHeader) { + this.contentTypeHeader = contentTypeHeader; + } + + public String getObjectMapper() { + return objectMapper; + } + + /** + * Lookup and use the existing ObjectMapper with the given id when using Jackson. + */ + public void setObjectMapper(String objectMapper) { + this.objectMapper = objectMapper; + } + + public String getUseDefaultObjectMapper() { + return useDefaultObjectMapper; + } + + /** + * Whether to lookup and use default Jackson ObjectMapper from the registry. + */ + public void setUseDefaultObjectMapper(String useDefaultObjectMapper) { + this.useDefaultObjectMapper = useDefaultObjectMapper; + } + + public String getPrettyPrint() { + return prettyPrint; + } + + /** + * To enable pretty printing output nicely formatted. + * <p/> + * Is by default false. + */ + public void setPrettyPrint(String prettyPrint) { + this.prettyPrint = prettyPrint; + } + + public String getUnmarshalTypeName() { + return unmarshalTypeName; + } + + /** + * Class name of the java type to use when unmarshalling + */ + public void setUnmarshalTypeName(String unmarshalTypeName) { + this.unmarshalTypeName = unmarshalTypeName; + } + + public Class<?> getUnmarshalType() { + return unmarshalType; + } + + /** + * Class of the java type to use when unmarshalling + */ + public void setUnmarshalType(Class<?> unmarshalType) { + 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; + } + + /** + * 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 setJsonView(Class<?> jsonView) { + this.jsonView = jsonView; + } + + public String getInclude() { + return include; + } + + /** + * 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 <tt>NON_NULL</tt> + */ + public void setInclude(String include) { + this.include = include; + } + + public String getAllowJmsType() { + return allowJmsType; + } + + /** + * Used for JMS users to allow the JMSType header from the JMS spec to specify a FQN classname to use to unmarshal + * to. + */ + public void setAllowJmsType(String allowJmsType) { + this.allowJmsType = allowJmsType; + } + + public String getCollectionTypeName() { + return collectionTypeName; + } + + /** + * 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. + */ + public void setCollectionTypeName(String collectionTypeName) { + this.collectionTypeName = collectionTypeName; + } + + public Class<?> getCollectionType() { + return collectionType; + } + + public void setCollectionType(Class<?> collectionType) { + this.collectionType = collectionType; + } + + public String getUseList() { + return useList; + } + + /** + * To unmarshal to a List of Map or a List of Pojo. + */ + public void setUseList(String useList) { + this.useList = useList; + } + + public String getModuleClassNames() { + return moduleClassNames; + } + + /** + * To use custom Jackson modules com.fasterxml.jackson.databind.Module specified as a String with FQN class names. + * Multiple classes can be separated by comma. + */ + public void setModuleClassNames(String moduleClassNames) { + this.moduleClassNames = moduleClassNames; + } + + public String getModuleRefs() { + return moduleRefs; + } + + /** + * To use custom Jackson modules referred from the Camel registry. Multiple modules can be separated by comma. + */ + public void setModuleRefs(String moduleRefs) { + this.moduleRefs = moduleRefs; + } + + public String getEnableFeatures() { + return enableFeatures; + } + + /** + * Set of features to enable on the Jackson <tt>com.fasterxml.jackson.databind.ObjectMapper</tt>. + * <p/> + * The features should be a name that matches a enum from + * <tt>com.fasterxml.jackson.databind.SerializationFeature</tt>, + * <tt>com.fasterxml.jackson.databind.DeserializationFeature</tt>, or + * <tt>com.fasterxml.jackson.databind.MapperFeature</tt> + * <p/> + * Multiple features can be separated by comma + */ + public void setEnableFeatures(String enableFeatures) { + this.enableFeatures = enableFeatures; + } + + public String getDisableFeatures() { + return disableFeatures; + } + + /** + * Set of features to disable on the Jackson <tt>com.fasterxml.jackson.databind.ObjectMapper</tt>. + * <p/> + * The features should be a name that matches a enum from + * <tt>com.fasterxml.jackson.databind.SerializationFeature</tt>, + * <tt>com.fasterxml.jackson.databind.DeserializationFeature</tt>, or + * <tt>com.fasterxml.jackson.databind.MapperFeature</tt> + * <p/> + * Multiple features can be separated by comma + */ + public void setDisableFeatures(String disableFeatures) { + this.disableFeatures = disableFeatures; + } + + public String getAllowUnmarshallType() { + return allowUnmarshallType; + } + + /** + * If enabled then Jackson is allowed to attempt to use the CamelJacksonUnmarshalType header during the + * unmarshalling. + * <p/> + * This should only be enabled when desired to be used. + */ + public void setAllowUnmarshallType(String allowUnmarshallType) { + this.allowUnmarshallType = allowUnmarshallType; + } + + public String getTimezone() { + return timezone; + } + + /** + * If set then Jackson will use the Timezone when marshalling/unmarshalling. + */ + public void setTimezone(String timezone) { + this.timezone = timezone; + } + + public String getAutoDiscoverObjectMapper() { + return autoDiscoverObjectMapper; + } + + /** + * If set to true then Jackson will lookup for an objectMapper into the registry + */ + public void setAutoDiscoverObjectMapper(String autoDiscoverObjectMapper) { + this.autoDiscoverObjectMapper = autoDiscoverObjectMapper; + } + + @Override + public String getDataFormatName() { + // json data format is special as the name can be from different bundles + return "protobuf-jackson"; + } + + // + // Fluent builders + // + + public ProtobufJacksonDataFormat objectMapper(String objectMapper) { + this.objectMapper = objectMapper; + return this; + } + + public ProtobufJacksonDataFormat useDefaultObjectMapper(boolean useDefaultObjectMapper) { + return useDefaultObjectMapper(Boolean.toString(useDefaultObjectMapper)); + } + + public ProtobufJacksonDataFormat useDefaultObjectMapper(String useDefaultObjectMapper) { + this.useDefaultObjectMapper = useDefaultObjectMapper; + return this; + } + + public ProtobufJacksonDataFormat prettyPrint(boolean prettyPrint) { + return prettyPrint(Boolean.toString(prettyPrint)); + } + + public ProtobufJacksonDataFormat prettyPrint(String prettyPrint) { + this.prettyPrint = prettyPrint; + return this; + } + + public ProtobufJacksonDataFormat unmarshalType(String unmarshalType) { + this.unmarshalTypeName = unmarshalType; + return this; + } + + public ProtobufJacksonDataFormat unmarshalType(Class<?> unmarshalType) { + this.unmarshalType = unmarshalType; + return this; + } + + public ProtobufJacksonDataFormat jsonView(Class<?> jsonView) { + this.jsonView = jsonView; + return this; + } + + public ProtobufJacksonDataFormat include(String include) { + this.include = include; + return this; + } + + public ProtobufJacksonDataFormat allowJmsType(boolean allowJmsType) { + return allowJmsType(Boolean.toString(allowJmsType)); + } + + public ProtobufJacksonDataFormat allowJmsType(String allowJmsType) { + this.allowJmsType = allowJmsType; + return this; + } + + public ProtobufJacksonDataFormat collectionType(String collectionType) { + this.collectionTypeName = collectionType; + return this; + } + + public ProtobufJacksonDataFormat collectionType(Class<?> collectionType) { + this.collectionType = collectionType; + return this; + } + + public ProtobufJacksonDataFormat useList(boolean useList) { + return useList(Boolean.toString(useList)); + } + + public ProtobufJacksonDataFormat useList(String useList) { + this.useList = useList; + return this; + } + + public ProtobufJacksonDataFormat moduleClassNames(String moduleClassNames) { + this.moduleClassNames = moduleClassNames; + return this; + } + + public ProtobufJacksonDataFormat moduleRefs(String moduleRefs) { + this.moduleRefs = moduleRefs; + return this; + } + + public ProtobufJacksonDataFormat enableFeatures(String enableFeatures) { + this.enableFeatures = enableFeatures; + return this; + } + + public ProtobufJacksonDataFormat disableFeatures(String disableFeatures) { + this.disableFeatures = disableFeatures; + return this; + } + + public ProtobufJacksonDataFormat allowUnmarshallType(boolean allowUnmarshallType) { + return allowUnmarshallType(Boolean.toString(allowUnmarshallType)); + } + + public ProtobufJacksonDataFormat allowUnmarshallType(String allowUnmarshallType) { + this.allowUnmarshallType = allowUnmarshallType; + return this; + } + + public ProtobufJacksonDataFormat timezone(String timezone) { + this.timezone = timezone; + return this; + } + + public ProtobufJacksonDataFormat autoDiscoverObjectMapper(boolean autoDiscoverObjectMapper) { + return autoDiscoverObjectMapper(Boolean.toString(autoDiscoverObjectMapper)); + } + + public ProtobufJacksonDataFormat autoDiscoverObjectMapper(String autoDiscoverObjectMapper) { + this.autoDiscoverObjectMapper = autoDiscoverObjectMapper; + return this; + } + +} diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/AvroJacksonDataFormatReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/AvroJacksonDataFormatReifier.java new file mode 100644 index 0000000..2286902 --- /dev/null +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/AvroJacksonDataFormatReifier.java @@ -0,0 +1,68 @@ +/* + * 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.reifier.dataformat; + +import java.util.Map; + +import org.apache.camel.CamelContext; +import org.apache.camel.model.DataFormatDefinition; +import org.apache.camel.model.dataformat.AvroJacksonDataFormat; + +public class AvroJacksonDataFormatReifier extends DataFormatReifier<AvroJacksonDataFormat> { + + public AvroJacksonDataFormatReifier(CamelContext camelContext, DataFormatDefinition definition) { + super(camelContext, (AvroJacksonDataFormat) definition); + } + + @Override + protected void prepareDataFormatConfig(Map<String, Object> properties) { + properties.put("objectMapper", asRef(definition.getObjectMapper())); + if (definition.getUseDefaultObjectMapper() == null) { + // default true + properties.put("useDefaultObjectMapper", "true"); + } else { + 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.getUnmarshalType() != null) { + properties.put("unmarshalTypeName", asTypeName(definition.getUnmarshalType())); + } else { + properties.put("unmarshalTypeName", definition.getUnmarshalTypeName()); + } + properties.put("prettyPrint", definition.getPrettyPrint()); + properties.put("jsonView", definition.getJsonView()); + properties.put("include", definition.getInclude()); + properties.put("allowJmsType", definition.getAllowJmsType()); + if (definition.getCollectionType() != null) { + properties.put("collectionTypeName", asTypeName(definition.getCollectionType())); + } else { + properties.put("collectionTypeName", definition.getCollectionTypeName()); + } + properties.put("useList", definition.getUseList()); + properties.put("moduleClassNames", definition.getModuleClassNames()); + properties.put("moduleRefs", definition.getModuleRefs()); + properties.put("enableFeatures", definition.getEnableFeatures()); + properties.put("disableFeatures", definition.getDisableFeatures()); + properties.put("allowUnmarshallType", definition.getAllowUnmarshallType()); + } + +} diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/DataFormatReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/DataFormatReifier.java index e10f28e..08559ac 100644 --- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/DataFormatReifier.java +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/DataFormatReifier.java @@ -28,6 +28,7 @@ import org.apache.camel.model.Model; import org.apache.camel.model.dataformat.ASN1DataFormat; import org.apache.camel.model.dataformat.Any23DataFormat; import org.apache.camel.model.dataformat.AvroDataFormat; +import org.apache.camel.model.dataformat.AvroJacksonDataFormat; import org.apache.camel.model.dataformat.BarcodeDataFormat; import org.apache.camel.model.dataformat.Base64DataFormat; import org.apache.camel.model.dataformat.BeanioDataFormat; @@ -53,6 +54,7 @@ import org.apache.camel.model.dataformat.LZFDataFormat; import org.apache.camel.model.dataformat.MimeMultipartDataFormat; import org.apache.camel.model.dataformat.PGPDataFormat; import org.apache.camel.model.dataformat.ProtobufDataFormat; +import org.apache.camel.model.dataformat.ProtobufJacksonDataFormat; import org.apache.camel.model.dataformat.RssDataFormat; import org.apache.camel.model.dataformat.SoapJaxbDataFormat; import org.apache.camel.model.dataformat.SyslogDataFormat; @@ -183,6 +185,8 @@ public abstract class DataFormatReifier<T extends DataFormatDefinition> extends return new ASN1DataFormatReifier(camelContext, definition); } else if (definition instanceof AvroDataFormat) { return new AvroDataFormatReifier(camelContext, definition); + } else if (definition instanceof AvroJacksonDataFormat) { + return new AvroJacksonDataFormatReifier(camelContext, definition); } else if (definition instanceof BarcodeDataFormat) { return new BarcodeDataFormatReifier(camelContext, definition); } else if (definition instanceof Base64DataFormat) { @@ -231,6 +235,8 @@ public abstract class DataFormatReifier<T extends DataFormatDefinition> extends return new PGPDataFormatReifier(camelContext, definition); } else if (definition instanceof ProtobufDataFormat) { return new ProtobufDataFormatReifier(camelContext, definition); + } else if (definition instanceof ProtobufJacksonDataFormat) { + return new ProtobufJacksonDataFormatReifier(camelContext, definition); } else if (definition instanceof RssDataFormat) { return new RssDataFormatReifier(camelContext, definition); } else if (definition instanceof SoapJaxbDataFormat) { diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/ProtobufJacksonDataFormatReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/ProtobufJacksonDataFormatReifier.java new file mode 100644 index 0000000..9f849ab --- /dev/null +++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/dataformat/ProtobufJacksonDataFormatReifier.java @@ -0,0 +1,68 @@ +/* + * 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.reifier.dataformat; + +import java.util.Map; + +import org.apache.camel.CamelContext; +import org.apache.camel.model.DataFormatDefinition; +import org.apache.camel.model.dataformat.ProtobufJacksonDataFormat; + +public class ProtobufJacksonDataFormatReifier extends DataFormatReifier<ProtobufJacksonDataFormat> { + + public ProtobufJacksonDataFormatReifier(CamelContext camelContext, DataFormatDefinition definition) { + super(camelContext, (ProtobufJacksonDataFormat) definition); + } + + @Override + protected void prepareDataFormatConfig(Map<String, Object> properties) { + properties.put("objectMapper", asRef(definition.getObjectMapper())); + if (definition.getUseDefaultObjectMapper() == null) { + // default true + properties.put("useDefaultObjectMapper", "true"); + } else { + 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.getUnmarshalType() != null) { + properties.put("unmarshalTypeName", asTypeName(definition.getUnmarshalType())); + } else { + properties.put("unmarshalTypeName", definition.getUnmarshalTypeName()); + } + properties.put("prettyPrint", definition.getPrettyPrint()); + properties.put("jsonView", definition.getJsonView()); + properties.put("include", definition.getInclude()); + properties.put("allowJmsType", definition.getAllowJmsType()); + if (definition.getCollectionType() != null) { + properties.put("collectionTypeName", asTypeName(definition.getCollectionType())); + } else { + properties.put("collectionTypeName", definition.getCollectionTypeName()); + } + properties.put("useList", definition.getUseList()); + properties.put("moduleClassNames", definition.getModuleClassNames()); + properties.put("moduleRefs", definition.getModuleRefs()); + properties.put("enableFeatures", definition.getEnableFeatures()); + properties.put("disableFeatures", definition.getDisableFeatures()); + properties.put("allowUnmarshallType", definition.getAllowUnmarshallType()); + } + +}
