You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by al...@apache.org on 2020/02/19 17:16:19 UTC
[camel-quarkus] branch master updated: Created a camel gson
extension #681
This is an automated email from the ASF dual-hosted git repository.
aldettinger pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/master by this push:
new 3ba3c24 Created a camel gson extension #681
3ba3c24 is described below
commit 3ba3c24d0c1b5b46b9001f21fc219d5e24e75487
Author: aldettinger <al...@gmail.com>
AuthorDate: Wed Feb 19 16:35:03 2020 +0100
Created a camel gson extension #681
---
.../pages/list-of-camel-quarkus-extensions.adoc | 4 +-
extensions/gson/deployment/pom.xml | 75 ++++++++++++++++++
.../component/gson/deployment/GsonProcessor.java | 21 ++---
extensions/gson/pom.xml | 39 +++++++++
extensions/gson/runtime/pom.xml | 82 +++++++++++++++++++
.../main/resources/META-INF/quarkus-extension.yaml | 27 +++++++
extensions/pom.xml | 1 +
extensions/readme.adoc | 4 +-
integration-tests/dataformats-json/pom.xml | 6 +-
.../component/jackson/JsonDataformatsRoute.java | 92 ++++++++++++++++------
.../component/jackson/model/DummyObject.java | 22 ++++--
.../model/{DummyObject.java => ExcludeField.java} | 23 ++----
.../src/main/resources/application.properties | 4 +-
...json-dataformats-routes.xml => gson-routes.xml} | 10 +--
...n-dataformats-routes.xml => jackson-routes.xml} | 4 +-
.../component/jackson/JsonComponentsTest.java | 12 +--
poms/bom-deployment/pom.xml | 5 ++
poms/bom/pom.xml | 10 +++
18 files changed, 366 insertions(+), 75 deletions(-)
diff --git a/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc b/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc
index c88fe48..4725d46 100644
--- a/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc
+++ b/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc
@@ -225,7 +225,7 @@ Number of Camel components: 65 in 56 JAR artifacts (0 deprecated)
== Camel Data Formats
// dataformats: START
-Number of Camel data formats: 13 in 10 JAR artifacts (0 deprecated)
+Number of Camel data formats: 14 in 11 JAR artifacts (0 deprecated)
[width="100%",cols="4,1,5",options="header"]
|===
@@ -245,6 +245,8 @@ Number of Camel data formats: 13 in 10 JAR artifacts (0 deprecated)
| xref:extensions/fhir.adoc[FHIR XML] (camel-quarkus-fhir) | 0.3.0 | The FHIR XML data format is used to marshall/unmarshall from/to FHIR objects to/from XML.
+| link:https://camel.apache.org/components/latest/json-gson-dataformat.html[JSon GSon] (camel-quarkus-gson) | 1.0.0 | JSon data format is used for unmarshal a JSon payload to POJO or to marshal POJO back to JSon payload.
+
| link:https://camel.apache.org/components/latest/json-jackson-dataformat.html[JSon Jackson] (camel-quarkus-jackson) | 0.3.0 | JSon data format is used for unmarshal a JSon payload to POJO or to marshal POJO back to JSon payload.
| link:https://camel.apache.org/components/latest/mime-multipart-dataformat.html[MIME Multipart] (camel-quarkus-mail) | 0.2.0 | The MIME Multipart data format is used for marshalling Camel messages with attachments into MIME-Multipart message, and vise-versa.
diff --git a/extensions/gson/deployment/pom.xml b/extensions/gson/deployment/pom.xml
new file mode 100644
index 0000000..e702434
--- /dev/null
+++ b/extensions/gson/deployment/pom.xml
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-gson-parent</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>camel-quarkus-gson-deployment</artifactId>
+ <name>Camel Quarkus :: Gson :: Deployment</name>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-bom-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-core-deployment</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-gson</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <annotationProcessorPaths>
+ <path>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-extension-processor</artifactId>
+ <version>${quarkus.version}</version>
+ </path>
+ </annotationProcessorPaths>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/jackson/model/DummyObject.java b/extensions/gson/deployment/src/main/java/org/apache/camel/quarkus/component/gson/deployment/GsonProcessor.java
similarity index 69%
copy from integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/jackson/model/DummyObject.java
copy to extensions/gson/deployment/src/main/java/org/apache/camel/quarkus/component/gson/deployment/GsonProcessor.java
index 4d6caed..e39f21d 100644
--- a/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/jackson/model/DummyObject.java
+++ b/extensions/gson/deployment/src/main/java/org/apache/camel/quarkus/component/gson/deployment/GsonProcessor.java
@@ -14,23 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.quarkus.component.jackson.model;
+package org.apache.camel.quarkus.component.gson.deployment;
-import io.quarkus.runtime.annotations.RegisterForReflection;
+import io.quarkus.deployment.annotations.BuildStep;
+import io.quarkus.deployment.builditem.FeatureBuildItem;
-@RegisterForReflection
-public class DummyObject {
+class GsonProcessor {
- private String dummy;
+ private static final String FEATURE = "camel-gson";
- public DummyObject() {
+ @BuildStep
+ FeatureBuildItem feature() {
+ return new FeatureBuildItem(FEATURE);
}
- public String getDummy() {
- return dummy;
- }
-
- public void setDummy(String dummy) {
- this.dummy = dummy;
- }
}
diff --git a/extensions/gson/pom.xml b/extensions/gson/pom.xml
new file mode 100644
index 0000000..4e683b0
--- /dev/null
+++ b/extensions/gson/pom.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-build-parent</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <relativePath>../../poms/build-parent/pom.xml</relativePath>
+ </parent>
+
+ <artifactId>camel-quarkus-gson-parent</artifactId>
+ <name>Camel Quarkus :: Gson</name>
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>deployment</module>
+ <module>runtime</module>
+ </modules>
+</project>
diff --git a/extensions/gson/runtime/pom.xml b/extensions/gson/runtime/pom.xml
new file mode 100644
index 0000000..851120b
--- /dev/null
+++ b/extensions/gson/runtime/pom.xml
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-gson-parent</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>camel-quarkus-gson</artifactId>
+ <name>Camel Quarkus :: Gson :: Runtime</name>
+
+ <properties>
+ <firstVersion>1.0.0</firstVersion>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-bom</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-gson</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-bootstrap-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <annotationProcessorPaths>
+ <path>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-extension-processor</artifactId>
+ <version>${quarkus.version}</version>
+ </path>
+ </annotationProcessorPaths>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/extensions/gson/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/gson/runtime/src/main/resources/META-INF/quarkus-extension.yaml
new file mode 100644
index 0000000..babc2a0
--- /dev/null
+++ b/extensions/gson/runtime/src/main/resources/META-INF/quarkus-extension.yaml
@@ -0,0 +1,27 @@
+#
+# 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.
+#
+
+---
+name: "Camel Quarkus Gson"
+description: "Camel Gson Data Format"
+metadata:
+ keywords:
+ - "camel"
+ - "gson"
+ guide: "https://quarkus.io/guides/camel"
+ categories:
+ - "integration"
diff --git a/extensions/pom.xml b/extensions/pom.xml
index 19fb5be..4a6ea79 100644
--- a/extensions/pom.xml
+++ b/extensions/pom.xml
@@ -73,6 +73,7 @@
<module>fhir</module>
<module>file</module>
<module>ftp</module>
+ <module>gson</module>
<module>http</module>
<module>hystrix</module>
<module>infinispan</module>
diff --git a/extensions/readme.adoc b/extensions/readme.adoc
index 43c33e5..776305b 100644
--- a/extensions/readme.adoc
+++ b/extensions/readme.adoc
@@ -213,7 +213,7 @@ Number of Camel components: 65 in 56 JAR artifacts (0 deprecated)
== Camel Data Formats
// dataformats: START
-Number of Camel data formats: 13 in 10 JAR artifacts (0 deprecated)
+Number of Camel data formats: 14 in 11 JAR artifacts (0 deprecated)
[width="100%",cols="4,1,5",options="header"]
|===
@@ -233,6 +233,8 @@ Number of Camel data formats: 13 in 10 JAR artifacts (0 deprecated)
| xref:extensions/fhir.adoc[FHIR XML] (camel-quarkus-fhir) | 0.3.0 | The FHIR XML data format is used to marshall/unmarshall from/to FHIR objects to/from XML.
+| link:https://camel.apache.org/components/latest/json-gson-dataformat.html[JSon GSon] (camel-quarkus-gson) | 1.0.0 | JSon data format is used for unmarshal a JSon payload to POJO or to marshal POJO back to JSon payload.
+
| link:https://camel.apache.org/components/latest/json-jackson-dataformat.html[JSon Jackson] (camel-quarkus-jackson) | 0.3.0 | JSon data format is used for unmarshal a JSon payload to POJO or to marshal POJO back to JSon payload.
| link:https://camel.apache.org/components/latest/mime-multipart-dataformat.html[MIME Multipart] (camel-quarkus-mail) | 0.2.0 | The MIME Multipart data format is used for marshalling Camel messages with attachments into MIME-Multipart message, and vise-versa.
diff --git a/integration-tests/dataformats-json/pom.xml b/integration-tests/dataformats-json/pom.xml
index 3994a91..90048ad 100644
--- a/integration-tests/dataformats-json/pom.xml
+++ b/integration-tests/dataformats-json/pom.xml
@@ -36,7 +36,7 @@
<!-- explicit dependencies of this module in the Maven sense, although they are required by the Quarkus Maven plugin. -->
<!-- Please update rule whenever you change the dependencies of this module by running -->
<!-- mvn process-resources -Pformat from the root directory -->
- <mvnd.builder.rule>camel-quarkus-core-xml-deployment,camel-quarkus-direct-deployment,camel-quarkus-jackson-deployment,camel-quarkus-log-deployment,camel-quarkus-support-policy-deployment,camel-quarkus-vm-deployment</mvnd.builder.rule>
+ <mvnd.builder.rule>camel-quarkus-core-xml-deployment,camel-quarkus-direct-deployment,camel-quarkus-gson-deployment,camel-quarkus-jackson-deployment,camel-quarkus-log-deployment,camel-quarkus-support-policy-deployment,camel-quarkus-vm-deployment</mvnd.builder.rule>
</properties>
<dependencies>
@@ -60,6 +60,10 @@
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-vm</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-gson</artifactId>
+ </dependency>
<dependency>
<groupId>io.quarkus</groupId>
diff --git a/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/jackson/JsonDataformatsRoute.java b/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/jackson/JsonDataformatsRoute.java
index 3e2cb94..88c2871 100644
--- a/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/jackson/JsonDataformatsRoute.java
+++ b/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/jackson/JsonDataformatsRoute.java
@@ -16,47 +16,93 @@
*/
package org.apache.camel.quarkus.component.jackson;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.List;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.PropertyNamingStrategy;
+import com.google.gson.ExclusionStrategy;
+import com.google.gson.FieldAttributes;
+import com.google.gson.FieldNamingPolicy;
+import com.google.gson.reflect.TypeToken;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.gson.GsonDataFormat;
import org.apache.camel.component.jackson.JacksonDataFormat;
import org.apache.camel.model.dataformat.JsonLibrary;
import org.apache.camel.quarkus.component.jackson.model.DummyObject;
+import org.apache.camel.quarkus.component.jackson.model.ExcludeField;
import org.apache.camel.quarkus.component.jackson.model.PojoA;
import org.apache.camel.quarkus.component.jackson.model.PojoB;
+import org.apache.camel.spi.DataFormat;
public class JsonDataformatsRoute extends RouteBuilder {
@Override
public void configure() {
- JacksonDataFormat format = new JacksonDataFormat(DummyObject.class);
- format.useList();
+ JacksonDataFormat jacksonDummyObjectDataFormat = new JacksonDataFormat(DummyObject.class);
+ jacksonDummyObjectDataFormat.useList();
+ ObjectMapper jacksonObjectMapper = new ObjectMapper();
+ jacksonObjectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
+ jacksonDummyObjectDataFormat.setObjectMapper(jacksonObjectMapper);
+ configureJsonRoutes(JsonLibrary.Jackson, jacksonDummyObjectDataFormat, new JacksonDataFormat(PojoA.class),
+ new JacksonDataFormat(PojoB.class));
+
+ GsonDataFormat gsonDummyObjectDataFormat = new GsonDataFormat();
+ Type genericType = new TypeToken<List<DummyObject>>() {
+ }.getType();
+ gsonDummyObjectDataFormat.setUnmarshalGenericType(genericType);
+ gsonDummyObjectDataFormat.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
+ gsonDummyObjectDataFormat.setExclusionStrategies(Arrays.<ExclusionStrategy> asList(new ExclusionStrategy() {
+ @Override
+ public boolean shouldSkipField(FieldAttributes f) {
+ return f.getAnnotation(ExcludeField.class) != null;
+ }
+
+ @Override
+ public boolean shouldSkipClass(Class<?> clazz) {
+ return false;
+ }
+ }));
+ configureJsonRoutes(JsonLibrary.Gson, gsonDummyObjectDataFormat, new GsonDataFormat(PojoA.class),
+ new GsonDataFormat(PojoB.class));
+ }
+
+ public void configureJsonRoutes(JsonLibrary library, DataFormat dummyObjectDataFormat, DataFormat pojoADataFormat,
+ DataFormat pojoBDataFormat) {
- from("direct:jackson-in")
- .wireTap("direct:jackson-tap")
+ fromF("direct:%s-in", library)
+ .wireTap("direct:" + library + "-tap")
.setBody(constant("ok"));
- from("direct:jackson-tap")
- .unmarshal(format)
- .to("log:jackson-out")
+
+ fromF("direct:%s-tap", library)
+ .unmarshal(dummyObjectDataFormat)
+ .toF("log:%s-out", library)
.split(body())
- .marshal(format)
+ .marshal(dummyObjectDataFormat)
.convertBodyTo(String.class)
- .to("vm:jackson-out");
- from("direct:jackson-in-a")
- .wireTap("direct:jackson-tap-a")
+ .toF("vm:%s-out", library);
+
+ fromF("direct:%s-in-a", library)
+ .wireTap("direct:" + library + "-tap-a")
.setBody(constant("ok"));
- from("direct:jackson-tap-a")
- .unmarshal().json(JsonLibrary.Jackson, PojoA.class)
- .to("log:jackson-out")
- .marshal(new JacksonDataFormat(PojoA.class))
+
+ fromF("direct:%s-tap-a", library)
+ .unmarshal().json(library, PojoA.class)
+ .toF("log:%s-out", library)
+ .marshal(pojoADataFormat)
.convertBodyTo(String.class)
- .to("vm:jackson-out-a");
- from("direct:jackson-in-b")
- .wireTap("direct:jackson-tap-b")
+ .toF("vm:%s-out-a", library);
+
+ fromF("direct:%s-in-b", library)
+ .wireTap("direct:" + library + "-tap-b")
.setBody(constant("ok"));
- from("direct:jackson-tap-b")
- .unmarshal().json(JsonLibrary.Jackson, PojoB.class)
- .to("log:jackson-out")
- .marshal(new JacksonDataFormat(PojoB.class))
+
+ fromF("direct:%s-tap-b", library)
+ .unmarshal().json(library, PojoB.class)
+ .toF("log:%s-out", library)
+ .marshal(pojoBDataFormat)
.convertBodyTo(String.class)
- .to("vm:jackson-out-b");
+ .toF("vm:%s-out-b", library);
}
}
diff --git a/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/jackson/model/DummyObject.java b/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/jackson/model/DummyObject.java
index 4d6caed..e0c1362 100644
--- a/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/jackson/model/DummyObject.java
+++ b/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/jackson/model/DummyObject.java
@@ -16,21 +16,33 @@
*/
package org.apache.camel.quarkus.component.jackson.model;
+import com.fasterxml.jackson.annotation.JsonIgnore;
import io.quarkus.runtime.annotations.RegisterForReflection;
@RegisterForReflection
public class DummyObject {
- private String dummy;
+ private String dummyString;
+ @JsonIgnore
+ @ExcludeField
+ private int ignored;
public DummyObject() {
}
- public String getDummy() {
- return dummy;
+ public String getDummyString() {
+ return dummyString;
}
- public void setDummy(String dummy) {
- this.dummy = dummy;
+ public void setDummyString(String dummy) {
+ this.dummyString = dummy;
+ }
+
+ public int getIgnored() {
+ return ignored;
+ }
+
+ public void setIgnored(int ignored) {
+ this.ignored = ignored;
}
}
diff --git a/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/jackson/model/DummyObject.java b/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/jackson/model/ExcludeField.java
similarity index 73%
copy from integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/jackson/model/DummyObject.java
copy to integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/jackson/model/ExcludeField.java
index 4d6caed..89efbac 100644
--- a/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/jackson/model/DummyObject.java
+++ b/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/jackson/model/ExcludeField.java
@@ -16,21 +16,12 @@
*/
package org.apache.camel.quarkus.component.jackson.model;
-import io.quarkus.runtime.annotations.RegisterForReflection;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
-@RegisterForReflection
-public class DummyObject {
-
- private String dummy;
-
- public DummyObject() {
- }
-
- public String getDummy() {
- return dummy;
- }
-
- public void setDummy(String dummy) {
- this.dummy = dummy;
- }
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ ElementType.FIELD })
+public @interface ExcludeField {
}
diff --git a/integration-tests/dataformats-json/src/main/resources/application.properties b/integration-tests/dataformats-json/src/main/resources/application.properties
index 4cc94ff..d78f73f 100644
--- a/integration-tests/dataformats-json/src/main/resources/application.properties
+++ b/integration-tests/dataformats-json/src/main/resources/application.properties
@@ -21,7 +21,7 @@ quarkus.ssl.native=true
quarkus.log.file.enable = false
# include xml routes in native image
-quarkus.native.additional-build-args = -H:IncludeResources=routes/json-dataformats-routes.xml
+quarkus.native.additional-build-args = -H:IncludeResources=routes/.*-routes.xml
#
# Camel
@@ -31,4 +31,4 @@ camel.context.name = camel-quarkus-integration-tests-dataformats-json
#
# Main
#
-camel.main.xml-routes = classpath:routes/json-dataformats-routes.xml
+camel.main.xml-routes = classpath:routes/jackson-routes.xml,classpath:routes/gson-routes.xml
diff --git a/integration-tests/dataformats-json/src/main/resources/routes/json-dataformats-routes.xml b/integration-tests/dataformats-json/src/main/resources/routes/gson-routes.xml
similarity index 79%
copy from integration-tests/dataformats-json/src/main/resources/routes/json-dataformats-routes.xml
copy to integration-tests/dataformats-json/src/main/resources/routes/gson-routes.xml
index 6c521e9..1caea24 100644
--- a/integration-tests/dataformats-json/src/main/resources/routes/json-dataformats-routes.xml
+++ b/integration-tests/dataformats-json/src/main/resources/routes/gson-routes.xml
@@ -24,19 +24,19 @@
http://camel.apache.org/schema/spring/camel-spring.xsd">
<route>
- <from uri="direct:jackson-type-as-attribute"/>
+ <from uri="direct:Gson-type-as-attribute"/>
<unmarshal>
- <json library="Jackson" unmarshalTypeName="org.apache.camel.quarkus.component.jackson.model.DummyObject"/>
+ <json library="Gson" unmarshalTypeName="org.apache.camel.quarkus.component.jackson.model.DummyObject"/>
</unmarshal>
</route>
<route>
- <from uri="direct:jackson-type-as-header"/>
- <setHeader name="CamelJacksonUnmarshalType">
+ <from uri="direct:Gson-type-as-header"/>
+ <setHeader name="CamelGsonUnmarshalType">
<constant>org.apache.camel.quarkus.component.jackson.model.DummyObject</constant>
</setHeader>
<unmarshal>
- <json library="Jackson" allowUnmarshallType="true"/>
+ <json library="Gson" allowUnmarshallType="true"/>
</unmarshal>
</route>
diff --git a/integration-tests/dataformats-json/src/main/resources/routes/json-dataformats-routes.xml b/integration-tests/dataformats-json/src/main/resources/routes/jackson-routes.xml
similarity index 93%
rename from integration-tests/dataformats-json/src/main/resources/routes/json-dataformats-routes.xml
rename to integration-tests/dataformats-json/src/main/resources/routes/jackson-routes.xml
index 6c521e9..3407026 100644
--- a/integration-tests/dataformats-json/src/main/resources/routes/json-dataformats-routes.xml
+++ b/integration-tests/dataformats-json/src/main/resources/routes/jackson-routes.xml
@@ -24,14 +24,14 @@
http://camel.apache.org/schema/spring/camel-spring.xsd">
<route>
- <from uri="direct:jackson-type-as-attribute"/>
+ <from uri="direct:Jackson-type-as-attribute"/>
<unmarshal>
<json library="Jackson" unmarshalTypeName="org.apache.camel.quarkus.component.jackson.model.DummyObject"/>
</unmarshal>
</route>
<route>
- <from uri="direct:jackson-type-as-header"/>
+ <from uri="direct:Jackson-type-as-header"/>
<setHeader name="CamelJacksonUnmarshalType">
<constant>org.apache.camel.quarkus.component.jackson.model.DummyObject</constant>
</setHeader>
diff --git a/integration-tests/dataformats-json/src/test/java/org/apache/camel/quarkus/component/jackson/JsonComponentsTest.java b/integration-tests/dataformats-json/src/test/java/org/apache/camel/quarkus/component/jackson/JsonComponentsTest.java
index c801a43..4386f27 100644
--- a/integration-tests/dataformats-json/src/test/java/org/apache/camel/quarkus/component/jackson/JsonComponentsTest.java
+++ b/integration-tests/dataformats-json/src/test/java/org/apache/camel/quarkus/component/jackson/JsonComponentsTest.java
@@ -34,7 +34,7 @@ import static org.hamcrest.Matchers.is;
public class JsonComponentsTest {
private static Stream<String> listJsonDataFormatsToBeTested() {
- return Stream.of("jackson");
+ return Stream.of("Jackson", "Gson");
}
@ParameterizedTest
@@ -42,18 +42,18 @@ public class JsonComponentsTest {
public void testRoutes(String jsonComponent) {
RestAssured.given().contentType(ContentType.TEXT)
.queryParam("json-component", jsonComponent)
- .body("[{\"dummy\": \"value1\"}, {\"dummy\": \"value2\"}]")
+ .body("[{\"dummy_string\": \"value1\"}, {\"dummy_string\": \"value2\"}]")
.post("/dataformats-json/in");
RestAssured.given()
.queryParam("json-component", jsonComponent)
.post("/dataformats-json/out")
.then()
- .body(equalTo("{\"dummy\":\"value1\"}"));
+ .body(equalTo("{\"dummy_string\":\"value1\"}"));
RestAssured.given()
.queryParam("json-component", jsonComponent)
.post("/dataformats-json/out")
.then()
- .body(equalTo("{\"dummy\":\"value2\"}"));
+ .body(equalTo("{\"dummy_string\":\"value2\"}"));
}
@ParameterizedTest
@@ -90,13 +90,13 @@ public class JsonComponentsTest {
@MethodSource("listDirectUrisFromXmlRoutesToBeTested")
public void testUnmarshal(String directId) {
DummyObject object = new DummyObject();
- object.setDummy("95f669ce-d287-4519-b212-4450bc791867");
+ object.setDummyString("95f669ce-d287-4519-b212-4450bc791867");
RestAssured.given()
.contentType(ContentType.TEXT)
.body(JsonbBuilder.create().toJson(object))
.post("/dataformats-json/unmarshal/{direct-id}", directId)
.then()
- .body("dummy", is(object.getDummy()));
+ .body("dummyString", is(object.getDummyString()));
}
}
diff --git a/poms/bom-deployment/pom.xml b/poms/bom-deployment/pom.xml
index c2650f7..e63d466 100644
--- a/poms/bom-deployment/pom.xml
+++ b/poms/bom-deployment/pom.xml
@@ -231,6 +231,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-gson-deployment</artifactId>
+ <version>${camel-quarkus.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-http-common-deployment</artifactId>
<version>${camel-quarkus.version}</version>
</dependency>
diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml
index 98f271a..e3d60d2 100644
--- a/poms/bom/pom.xml
+++ b/poms/bom/pom.xml
@@ -254,6 +254,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-gson</artifactId>
+ <version>${camel.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-headersmap</artifactId>
<version>${camel.version}</version>
</dependency>
@@ -730,6 +735,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-gson</artifactId>
+ <version>${camel-quarkus.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-http</artifactId>
<version>${camel-quarkus.version}</version>
</dependency>