This is an automated email from the ASF dual-hosted git repository. ppalaga pushed a commit to branch camel-master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 1e0df40b28a48044cff3d62bc71baf3112e14ab0 Author: JiriOndrusek <[email protected]> AuthorDate: Thu Nov 5 13:02:17 2020 +0100 JSON-B data format support #1973 --- catalog/pom.xml | 13 ++ .../ROOT/pages/reference/extensions/jsonb.adoc | 38 ++++++ .../partials/reference/dataformats/json-jsonb.adoc | 14 +- extensions/jsonb/deployment/pom.xml | 67 ++++++++++ .../component/jsonb/deployment/JsonbProcessor.java | 22 ++-- extensions/jsonb/pom.xml | 39 ++++++ extensions/jsonb/runtime/pom.xml | 128 ++++++++++++++++++ .../jsonb/runtime/src/main/doc/configuration.adoc | 1 + .../main/resources/META-INF/quarkus-extension.yaml | 31 +++++ extensions/pom.xml | 1 + integration-tests/dataformats-json/pom.xml | 17 +++ .../dataformats/json/JsonDataformatsRoute.java | 8 +- .../component/dataformats/json/ParamType.java | 143 +++++++++++++++++++++ .../dataformats/json/model/DummyObject.java | 11 ++ .../component/dataformats/json/model/PojoA.java | 6 + .../component/dataformats/json/model/PojoB.java | 8 +- .../src/main/resources/application.properties | 2 +- .../src/main/resources/routes/jsonb-routes.xml | 43 +++++++ .../dataformats/json/JsonComponentsTest.java | 2 +- poms/bom/pom.xml | 15 +++ 20 files changed, 590 insertions(+), 19 deletions(-) diff --git a/catalog/pom.xml b/catalog/pom.xml index 09745bb..19e46f5 100644 --- a/catalog/pom.xml +++ b/catalog/pom.xml @@ -2207,6 +2207,19 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jsonb</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-jsonpath</artifactId> <version>${project.version}</version> <type>pom</type> diff --git a/docs/modules/ROOT/pages/reference/extensions/jsonb.adoc b/docs/modules/ROOT/pages/reference/extensions/jsonb.adoc new file mode 100644 index 0000000..1b8038b --- /dev/null +++ b/docs/modules/ROOT/pages/reference/extensions/jsonb.adoc @@ -0,0 +1,38 @@ +// Do not edit directly! +// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page += JSON-B +:cq-artifact-id: camel-quarkus-jsonb +:cq-native-supported: true +:cq-status: Stable +:cq-description: Marshal POJOs to JSON and back using JSON-B. +:cq-deprecated: false +:cq-jvm-since: 1.5.0 +:cq-native-since: 1.5.0 + +[.badges] +[.badge-key]##JVM since##[.badge-supported]##1.5.0## [.badge-key]##Native since##[.badge-supported]##1.5.0## + +Marshal POJOs to JSON and back using JSON-B. + +== What's inside + +* xref:latest@components:dataformats:json-jsonb-dataformat.adoc[JSON JSON-B data format] + +Please refer to the above link for usage and configuration details. + +== Maven coordinates + +[source,xml] +---- +<dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jsonb</artifactId> +</dependency> +---- + +Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications. + +== Additional Camel Quarkus configuration + +Extension contains `io.quarkus:quarkus-jsonb` dependency. No jsonb implementation has to be provided. + diff --git a/docs/modules/ROOT/partials/reference/dataformats/json-jsonb.adoc b/docs/modules/ROOT/partials/reference/dataformats/json-jsonb.adoc index a509c1d..c46d126 100644 --- a/docs/modules/ROOT/partials/reference/dataformats/json-jsonb.adoc +++ b/docs/modules/ROOT/partials/reference/dataformats/json-jsonb.adoc @@ -1 +1,13 @@ -// Empty partial for a Camel bit unsupported by Camel Quarkus to avoid warnings when this file is included from a Camel page +// Do not edit directly! +// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page +:cq-artifact-id: camel-quarkus-jsonb +:cq-artifact-id-base: jsonb +:cq-native-supported: true +:cq-status: Stable +:cq-deprecated: false +:cq-jvm-since: 1.5.0 +:cq-native-since: 1.5.0 +:cq-camel-part-name: json-jsonb +:cq-camel-part-title: JSON JSON-B +:cq-camel-part-description: Marshal POJOs to JSON and back using JSON-B. +:cq-extension-page-title: JSON-B diff --git a/extensions/jsonb/deployment/pom.xml b/extensions/jsonb/deployment/pom.xml new file mode 100644 index 0000000..c3cb66e --- /dev/null +++ b/extensions/jsonb/deployment/pom.xml @@ -0,0 +1,67 @@ +<?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-jsonb-parent</artifactId> + <version>1.5.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-jsonb-deployment</artifactId> + <name>Camel Quarkus :: JSON-B :: Deployment</name> + + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-core-deployment</artifactId> + </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-jsonb-deployment</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jsonb</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/dataformats/json/model/PojoB.java b/extensions/jsonb/deployment/src/main/java/org/apache/camel/quarkus/component/jsonb/deployment/JsonbProcessor.java similarity index 69% copy from integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/json/model/PojoB.java copy to extensions/jsonb/deployment/src/main/java/org/apache/camel/quarkus/component/jsonb/deployment/JsonbProcessor.java index 74d6e5d..165ff79 100644 --- a/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/json/model/PojoB.java +++ b/extensions/jsonb/deployment/src/main/java/org/apache/camel/quarkus/component/jsonb/deployment/JsonbProcessor.java @@ -14,23 +14,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.quarkus.component.dataformats.json.model; +package org.apache.camel.quarkus.component.jsonb.deployment; -import io.quarkus.runtime.annotations.RegisterForReflection; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.FeatureBuildItem; -@RegisterForReflection -public class PojoB { +class JsonbProcessor { - private Double value; + private static final String FEATURE = "camel-jsonb"; - public PojoB() { - } - - public Double getValue() { - return value; - } - - public void setString(Double string) { - this.value = string; + @BuildStep + FeatureBuildItem feature() { + return new FeatureBuildItem(FEATURE); } } diff --git a/extensions/jsonb/pom.xml b/extensions/jsonb/pom.xml new file mode 100644 index 0000000..f5c7b2a --- /dev/null +++ b/extensions/jsonb/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.5.0-SNAPSHOT</version> + <relativePath>../../poms/build-parent/pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-jsonb-parent</artifactId> + <name>Camel Quarkus :: JSON-B</name> + <packaging>pom</packaging> + + <modules> + <module>deployment</module> + <module>runtime</module> + </modules> +</project> diff --git a/extensions/jsonb/runtime/pom.xml b/extensions/jsonb/runtime/pom.xml new file mode 100644 index 0000000..f2be6bd --- /dev/null +++ b/extensions/jsonb/runtime/pom.xml @@ -0,0 +1,128 @@ +<?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-jsonb-parent</artifactId> + <version>1.5.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-jsonb</artifactId> + <name>Camel Quarkus :: JSON-B :: Runtime</name> + <description>Marshal POJOs to JSON and back using JSON-B.</description> + + <properties> + <camel.quarkus.jvmSince>1.5.0</camel.quarkus.jvmSince> + <camel.quarkus.nativeSince>1.5.0</camel.quarkus.nativeSince> + </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>io.quarkus</groupId> + <artifactId>quarkus-jsonb</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-jsonb</artifactId> + <exclusions> + <!-- we prefer the org.eclipse:yasson implementation coming via io.quarkus:quarkus-jsonb --> + <exclusion> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>*</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-jsonb_1.0_spec</artifactId> + </exclusion> + </exclusions> + </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> + + + <profiles> + <profile> + <id>full</id> + <activation> + <property> + <name>!quickly</name> + </property> + </activation> + <build> + <plugins> + <plugin> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-maven-plugin</artifactId> + <executions> + <execution> + <id>update-extension-doc-page</id> + <goals> + <goal>update-extension-doc-page</goal> + </goals> + <phase>process-classes</phase> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> diff --git a/extensions/jsonb/runtime/src/main/doc/configuration.adoc b/extensions/jsonb/runtime/src/main/doc/configuration.adoc new file mode 100644 index 0000000..5487a90 --- /dev/null +++ b/extensions/jsonb/runtime/src/main/doc/configuration.adoc @@ -0,0 +1 @@ +Extension contains `io.quarkus:quarkus-jsonb` dependency. No jsonb implementation has to be provided. \ No newline at end of file diff --git a/extensions/jsonb/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/jsonb/runtime/src/main/resources/META-INF/quarkus-extension.yaml new file mode 100644 index 0000000..ab14dff --- /dev/null +++ b/extensions/jsonb/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -0,0 +1,31 @@ +# +# 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. +# + +# This is a generated file. Do not edit directly! +# To re-generate, run the following command from the top level directory: +# +# mvn -N cq:update-quarkus-metadata +# +--- +name: "Camel JSON-B" +description: "Marshal POJOs to JSON and back using JSON-B" +metadata: + guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/jsonb.html" + categories: + - "integration" + status: + - "stable" diff --git a/extensions/pom.xml b/extensions/pom.xml index c853c44..a29085f 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -136,6 +136,7 @@ <module>jsch</module> <module>jslt</module> <module>json-validator</module> + <module>jsonb</module> <module>jsonpath</module> <module>jta</module> <module>kafka</module> diff --git a/integration-tests/dataformats-json/pom.xml b/integration-tests/dataformats-json/pom.xml index 8fc5dff..01d619f 100644 --- a/integration-tests/dataformats-json/pom.xml +++ b/integration-tests/dataformats-json/pom.xml @@ -48,6 +48,10 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jsonb</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-direct</artifactId> </dependency> <dependency> @@ -164,6 +168,19 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jsonb-deployment</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-log-deployment</artifactId> <version>${project.version}</version> <type>pom</type> diff --git a/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/json/JsonDataformatsRoute.java b/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/json/JsonDataformatsRoute.java index dc3a1ae..4d8aa47 100644 --- a/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/json/JsonDataformatsRoute.java +++ b/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/json/JsonDataformatsRoute.java @@ -30,6 +30,7 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.gson.GsonDataFormat; import org.apache.camel.component.jackson.JacksonDataFormat; import org.apache.camel.component.johnzon.JohnzonDataFormat; +import org.apache.camel.component.jsonb.JsonbDataFormat; import org.apache.camel.model.dataformat.JsonLibrary; import org.apache.camel.quarkus.component.dataformats.json.model.DummyObject; import org.apache.camel.quarkus.component.dataformats.json.model.ExcludeField; @@ -51,7 +52,8 @@ public class JsonDataformatsRoute extends RouteBuilder { new JacksonDataFormat(PojoB.class)); JohnzonDataFormat johnzonDummyObjectDataFormat = new JohnzonDataFormat(); - johnzonDummyObjectDataFormat.setParameterizedType(new JohnzonParameterizedType(List.class, DummyObject.class)); + johnzonDummyObjectDataFormat.setParameterizedType(new JohnzonParameterizedType(List.class, + DummyObject.class)); configureJsonRoutes(JsonLibrary.Johnzon, johnzonDummyObjectDataFormat, new JohnzonDataFormat(PojoA.class), new JohnzonDataFormat(PojoB.class)); @@ -74,6 +76,10 @@ public class JsonDataformatsRoute extends RouteBuilder { configureJsonRoutes(JsonLibrary.Gson, gsonDummyObjectDataFormat, new GsonDataFormat(PojoA.class), new GsonDataFormat(PojoB.class)); + JsonbDataFormat jsonBDummyObjectDataFormat = new JsonbDataFormat(new ParamType(List.class, DummyObject.class)); + configureJsonRoutes(JsonLibrary.Jsonb, jsonBDummyObjectDataFormat, new JsonbDataFormat(PojoA.class), + new JsonbDataFormat(PojoB.class)); + from("direct:jacksonxml-marshal") .marshal() .jacksonxml(true); diff --git a/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/json/ParamType.java b/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/json/ParamType.java new file mode 100644 index 0000000..68afb95 --- /dev/null +++ b/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/json/ParamType.java @@ -0,0 +1,143 @@ +/* + * 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.quarkus.component.dataformats.json; + +/* + * 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. + */ +/* + * 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. + */ +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.Arrays; + +public class ParamType implements ParameterizedType { + private final Type rawType; + private final Type[] types; + + public ParamType(final Type raw, final Type... types) { + if (raw == null) { + final ParameterizedType userFinalType = findUserParameterizedType(); + this.rawType = userFinalType.getRawType(); + this.types = userFinalType.getActualTypeArguments(); + } else { + this.rawType = raw; + this.types = types; + } + } + + private ParameterizedType findUserParameterizedType() { + final Type genericSuperclass = getClass().getGenericSuperclass(); + if (!ParameterizedType.class.isInstance(genericSuperclass)) { + throw new IllegalArgumentException("raw can be null only for children classes"); + } + final ParameterizedType pt = ParameterizedType.class.cast(genericSuperclass); // our type, then unwrap it + + final Type userType = pt.getActualTypeArguments()[0]; + if (!ParameterizedType.class.isInstance(userType)) { + throw new IllegalArgumentException("You need to pass a parameterized type to Johnzon*Types"); + } + + return ParameterizedType.class.cast(userType); + } + + @Override + public Type[] getActualTypeArguments() { + return types.clone(); + } + + @Override + public Type getOwnerType() { + return null; + } + + @Override + public Type getRawType() { + return rawType; + } + + @Override + public int hashCode() { + return Arrays.hashCode(types) ^ (rawType == null ? 0 : rawType.hashCode()); + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } else if (obj instanceof ParameterizedType) { + final ParameterizedType that = (ParameterizedType) obj; + final Type thatRawType = that.getRawType(); + return that.getOwnerType() == null + && (rawType == null ? thatRawType == null : rawType.equals(thatRawType)) + && Arrays.equals(types, that.getActualTypeArguments()); + } else { + return false; + } + } + + @Override + public String toString() { + final StringBuilder buffer = new StringBuilder(); + buffer.append(((Class<?>) rawType).getSimpleName()); + final Type[] actualTypes = getActualTypeArguments(); + if (actualTypes.length > 0) { + buffer.append("<"); + int length = actualTypes.length; + for (int i = 0; i < length; i++) { + buffer.append(actualTypes[i].toString()); + if (i != actualTypes.length - 1) { + buffer.append(","); + } + } + + buffer.append(">"); + } + return buffer.toString(); + } +} diff --git a/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/json/model/DummyObject.java b/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/json/model/DummyObject.java index 475946b..1888d89 100644 --- a/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/json/model/DummyObject.java +++ b/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/json/model/DummyObject.java @@ -16,6 +16,9 @@ */ package org.apache.camel.quarkus.component.dataformats.json.model; +import javax.json.bind.annotation.JsonbProperty; +import javax.json.bind.annotation.JsonbTransient; + import com.fasterxml.jackson.annotation.JsonIgnore; import io.quarkus.runtime.annotations.RegisterForReflection; import org.apache.johnzon.mapper.JohnzonIgnore; @@ -25,11 +28,13 @@ import org.apache.johnzon.mapper.JohnzonProperty; public class DummyObject { @JohnzonProperty("dummy_string") + @JsonbProperty("dummy_string") private String dummyString; @JohnzonIgnore @JsonIgnore @ExcludeField + @JsonbTransient private int ignored; public DummyObject() { @@ -50,4 +55,10 @@ public class DummyObject { public void setIgnored(int ignored) { this.ignored = ignored; } + + @Override + public String toString() { + return "DummyObject [dummyString=" + dummyString + ", ignored=" + ignored + "]"; + } + } diff --git a/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/json/model/PojoA.java b/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/json/model/PojoA.java index f6c2fab..366c9f5 100644 --- a/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/json/model/PojoA.java +++ b/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/json/model/PojoA.java @@ -37,4 +37,10 @@ public class PojoA { public void setName(String name) { this.name = name; } + + @Override + public String toString() { + return "PojoA [name=" + name + "]"; + } + } diff --git a/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/json/model/PojoB.java b/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/json/model/PojoB.java index 74d6e5d..b591044 100644 --- a/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/json/model/PojoB.java +++ b/integration-tests/dataformats-json/src/main/java/org/apache/camel/quarkus/component/dataformats/json/model/PojoB.java @@ -30,7 +30,13 @@ public class PojoB { return value; } - public void setString(Double string) { + public void setValue(Double string) { this.value = string; } + + @Override + public String toString() { + return "PojoB [value=" + value + "]"; + } + } diff --git a/integration-tests/dataformats-json/src/main/resources/application.properties b/integration-tests/dataformats-json/src/main/resources/application.properties index 70600cc..1767f72 100644 --- a/integration-tests/dataformats-json/src/main/resources/application.properties +++ b/integration-tests/dataformats-json/src/main/resources/application.properties @@ -27,4 +27,4 @@ camel.context.name = camel-quarkus-integration-tests-dataformats-json # # Main # -camel.main.xml-routes = classpath:routes/jackson-routes.xml,classpath:routes/johnzon-routes.xml,classpath:routes/gson-routes.xml +camel.main.xml-routes = classpath:routes/jsonb-routes.xml,classpath:routes/jackson-routes.xml,classpath:routes/johnzon-routes.xml,classpath:routes/gson-routes.xml diff --git a/integration-tests/dataformats-json/src/main/resources/routes/jsonb-routes.xml b/integration-tests/dataformats-json/src/main/resources/routes/jsonb-routes.xml new file mode 100644 index 0000000..261e88f --- /dev/null +++ b/integration-tests/dataformats-json/src/main/resources/routes/jsonb-routes.xml @@ -0,0 +1,43 @@ +<?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. + +--> +<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://camel.apache.org/schema/spring" + xsi:schemaLocation=" + http://camel.apache.org/schema/spring + http://camel.apache.org/schema/spring/camel-spring.xsd"> + + <route> + <from uri="direct:Jsonb-type-as-attribute"/> + <unmarshal> + <json library="Jsonb" unmarshalTypeName="org.apache.camel.quarkus.component.dataformats.json.model.AnotherObject"/> + </unmarshal> + </route> + + <route> + <from uri="direct:Jsonb-type-as-header"/> + <setHeader name="CamelJsonbUnmarshalType"> + <constant>org.apache.camel.quarkus.component.dataformats.json.model.AnotherObject</constant> + </setHeader> + <unmarshal> + <json library="Jsonb" /> + </unmarshal> + </route> + +</routes> \ No newline at end of file diff --git a/integration-tests/dataformats-json/src/test/java/org/apache/camel/quarkus/component/dataformats/json/JsonComponentsTest.java b/integration-tests/dataformats-json/src/test/java/org/apache/camel/quarkus/component/dataformats/json/JsonComponentsTest.java index 44c7ab3..8404431 100644 --- a/integration-tests/dataformats-json/src/test/java/org/apache/camel/quarkus/component/dataformats/json/JsonComponentsTest.java +++ b/integration-tests/dataformats-json/src/test/java/org/apache/camel/quarkus/component/dataformats/json/JsonComponentsTest.java @@ -36,7 +36,7 @@ import static org.hamcrest.Matchers.is; public class JsonComponentsTest { private static Stream<String> listJsonDataFormatsToBeTested() { - return Stream.of("Jackson", "Johnzon", "Gson"); + return Stream.of("Jackson", "Johnzon", "Gson", "Jsonb"); } @ParameterizedTest diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml index bec05c2..ac6aef3 100644 --- a/poms/bom/pom.xml +++ b/poms/bom/pom.xml @@ -1259,6 +1259,11 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-jsonb</artifactId> + <version>${camel.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-jsonpath</artifactId> <version>${camel.version}</version> </dependency> @@ -3733,6 +3738,16 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jsonb</artifactId> + <version>${camel-quarkus.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jsonb-deployment</artifactId> + <version>${camel-quarkus.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-jsonpath</artifactId> <version>${camel-quarkus.version}</version> </dependency>
