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 2021/08/03 11:09:24 UTC
[camel-quarkus] branch main updated: jolt: remove the
DeepCopySubstitution in favor of Quarkus serialization support #1433
This is an automated email from the ASF dual-hosted git repository.
aldettinger pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new 1fac87f jolt: remove the DeepCopySubstitution in favor of Quarkus serialization support #1433
1fac87f is described below
commit 1fac87f04c4a1fea2b1c5b7e06588e4362d7dbeb
Author: aldettinger <al...@gmail.com>
AuthorDate: Mon Aug 2 16:16:54 2021 +0200
jolt: remove the DeepCopySubstitution in favor of Quarkus serialization support #1433
---
.../deployment/CamelSerializationProcessor.java | 2 +
.../component/jolt/deployment/JoltProcessor.java | 8 +++
.../component/jolt/DeepCopySubstitution.java | 32 ------------
.../component/jolt/DeepCopySubstitutionTest.java | 61 ----------------------
.../quarkus/component/jolt/it/JoltResource.java | 4 +-
.../jolt/src/main/resources/defaultr.json | 10 +++-
.../camel/quarkus/component/jolt/it/JoltTest.java | 3 +-
7 files changed, 23 insertions(+), 97 deletions(-)
diff --git a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelSerializationProcessor.java b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelSerializationProcessor.java
index 26fcfd3..ea0821e 100644
--- a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelSerializationProcessor.java
+++ b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelSerializationProcessor.java
@@ -20,6 +20,7 @@ import java.math.BigInteger;
import java.util.AbstractCollection;
import java.util.AbstractList;
import java.util.AbstractMap;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
@@ -44,6 +45,7 @@ public class CamelSerializationProcessor {
AbstractCollection.class.getName(),
AbstractList.class.getName(),
AbstractMap.class.getName(),
+ ArrayList.class.getName(),
BigInteger.class.getName(),
Boolean.class.getName(),
Byte.class.getName(),
diff --git a/extensions/jolt/deployment/src/main/java/org/apache/camel/quarkus/component/jolt/deployment/JoltProcessor.java b/extensions/jolt/deployment/src/main/java/org/apache/camel/quarkus/component/jolt/deployment/JoltProcessor.java
index d572309..d848b7b 100644
--- a/extensions/jolt/deployment/src/main/java/org/apache/camel/quarkus/component/jolt/deployment/JoltProcessor.java
+++ b/extensions/jolt/deployment/src/main/java/org/apache/camel/quarkus/component/jolt/deployment/JoltProcessor.java
@@ -21,6 +21,7 @@ import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
+import org.apache.camel.quarkus.core.deployment.spi.CamelSerializationBuildItem;
class JoltProcessor {
@@ -37,4 +38,11 @@ class JoltProcessor {
producer.produce(new ReflectiveClassBuildItem(false, false, c));
});
}
+
+ @BuildStep
+ void registerJsonTypesForSerialization(BuildProducer<CamelSerializationBuildItem> producer) {
+ // A JOLT Defaultr transformation spec is a JSON content and it needs to be serialized at some point.
+ // As such, we need to register all JSON base types and super types for serialization.
+ producer.produce(new CamelSerializationBuildItem());
+ }
}
diff --git a/extensions/jolt/runtime/src/main/java/org/apache/camel/quarkus/component/jolt/DeepCopySubstitution.java b/extensions/jolt/runtime/src/main/java/org/apache/camel/quarkus/component/jolt/DeepCopySubstitution.java
deleted file mode 100644
index b774d51..0000000
--- a/extensions/jolt/runtime/src/main/java/org/apache/camel/quarkus/component/jolt/DeepCopySubstitution.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.jolt;
-
-import com.bazaarvoice.jolt.JsonUtils;
-import com.bazaarvoice.jolt.common.DeepCopy;
-import com.oracle.svm.core.annotate.Substitute;
-import com.oracle.svm.core.annotate.TargetClass;
-
-@TargetClass(DeepCopy.class)
-@Substitute
-final class DeepCopySubstitution {
-
- @Substitute
- public static Object simpleDeepCopy(Object toCopy) {
- return JsonUtils.cloneJson(toCopy);
- }
-}
diff --git a/extensions/jolt/runtime/src/test/java/org/apache/camel/quarkus/component/jolt/DeepCopySubstitutionTest.java b/extensions/jolt/runtime/src/test/java/org/apache/camel/quarkus/component/jolt/DeepCopySubstitutionTest.java
deleted file mode 100644
index 81401a8..0000000
--- a/extensions/jolt/runtime/src/test/java/org/apache/camel/quarkus/component/jolt/DeepCopySubstitutionTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.jolt;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.LinkedHashMap;
-import java.util.Objects;
-
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertNotSame;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-public class DeepCopySubstitutionTest {
-
- @SuppressWarnings("unchecked")
- @Test
- void nominalSchemaDeepCopyShouldSucceed() {
- LinkedHashMap<String, Object> originalLinkedHashMap = new LinkedHashMap<>();
- ArrayList<Integer> originalArrayList = new ArrayList<>(Arrays.asList(new Integer(10)));
-
- originalLinkedHashMap.put("boolean", new Boolean(true));
- originalLinkedHashMap.put("string", "original");
- originalLinkedHashMap.put("list", originalArrayList);
- originalLinkedHashMap.put("null", null);
-
- Object copiedLinkedHashMapObject = DeepCopySubstitution.simpleDeepCopy(originalLinkedHashMap);
-
- assertTrue(copiedLinkedHashMapObject instanceof LinkedHashMap);
- LinkedHashMap<String, Object> copiedLinkHashMap = (LinkedHashMap<String, Object>) copiedLinkedHashMapObject;
- Object copiedArrayListObject = copiedLinkHashMap.get("list");
- assertTrue(copiedArrayListObject instanceof ArrayList);
- ArrayList<Integer> copiedArrayList = (ArrayList<Integer>) copiedArrayListObject;
-
- assertTrue(Objects.deepEquals(originalLinkedHashMap, copiedLinkHashMap));
-
- assertNotSame(originalLinkedHashMap, copiedLinkHashMap);
- assertNotSame(originalLinkedHashMap.get("boolean"), copiedLinkHashMap.get("boolean"));
- assertNotSame(originalLinkedHashMap.get("string"), copiedLinkHashMap.get("string"));
- assertNotSame(originalArrayList, copiedArrayList);
- assertNotSame(originalArrayList.get(0), copiedArrayList.get(0));
- assertNull(copiedLinkHashMap.get("null"));
- }
-
-}
diff --git a/integration-tests/jolt/src/main/java/org/apache/camel/quarkus/component/jolt/it/JoltResource.java b/integration-tests/jolt/src/main/java/org/apache/camel/quarkus/component/jolt/it/JoltResource.java
index 0fb01b9..d09e53a 100644
--- a/integration-tests/jolt/src/main/java/org/apache/camel/quarkus/component/jolt/it/JoltResource.java
+++ b/integration-tests/jolt/src/main/java/org/apache/camel/quarkus/component/jolt/it/JoltResource.java
@@ -49,7 +49,9 @@ public class JoltResource {
Map<String, String> inbody = new HashMap<>();
inbody.put("key", value);
Map<?, ?> outBody = template.requestBody("jolt:defaultr.json?transformDsl=Defaultr", inbody, Map.class);
- return String.format("%s-%s+%s", outBody.get("a"), outBody.get("b"), outBody.get("key"));
+ Map<?, ?> outObject = (Map<?, ?>) outBody.get("object");
+ return String.format("%s-%s-%s-%s-%s-%s+%s", outBody.get("string"), outBody.get("null"), outBody.get("array"),
+ outBody.get("floating"), outBody.get("integer"), outObject.get("boolean"), outBody.get("key"));
}
@Path("/removr")
diff --git a/integration-tests/jolt/src/main/resources/defaultr.json b/integration-tests/jolt/src/main/resources/defaultr.json
index d166f55..356b6df 100644
--- a/integration-tests/jolt/src/main/resources/defaultr.json
+++ b/integration-tests/jolt/src/main/resources/defaultr.json
@@ -1,4 +1,10 @@
{
- "a": "aa",
- "b": "bb"
+ "string": "myString",
+ "null": null,
+ "array": [1, "2"],
+ "floating": 3.1,
+ "integer": 3,
+ "object" : {
+ "boolean": true
+ }
}
diff --git a/integration-tests/jolt/src/test/java/org/apache/camel/quarkus/component/jolt/it/JoltTest.java b/integration-tests/jolt/src/test/java/org/apache/camel/quarkus/component/jolt/it/JoltTest.java
index ae45609..b2cc59c 100644
--- a/integration-tests/jolt/src/test/java/org/apache/camel/quarkus/component/jolt/it/JoltTest.java
+++ b/integration-tests/jolt/src/test/java/org/apache/camel/quarkus/component/jolt/it/JoltTest.java
@@ -32,7 +32,8 @@ class JoltTest {
@Test
public void defaultrShouldSucceed() {
- given().body("myValue").put("/jolt/defaultr").then().statusCode(200).body(is("aa-bb+myValue"));
+ given().body("myValue").put("/jolt/defaultr").then().statusCode(200)
+ .body(is("myString-null-[1, 2]-3.1-3-true+myValue"));
}
@Test