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 fbc1862 Fix JSON keys are unquoted when using writeAsString in native
mode #3571
fbc1862 is described below
commit fbc18628c7676acab6704ccaa71552beff7c4795
Author: aldettinger <[email protected]>
AuthorDate: Wed Feb 23 15:40:31 2022 +0100
Fix JSON keys are unquoted when using writeAsString in native mode #3571
---
.../json/path/deployment/JsonPathProcessor.java | 2 ++
.../component/json/path/it/JsonPathResource.java | 21 ++++++++++++++
.../component/json/path/it/JsonPathTestRoute.java | 3 ++
.../json/path/it/JsonPathWriteAsStringIT.java | 24 ++++++++++++++++
.../json/path/it/JsonPathWriteAsStringTest.java | 33 ++++++++++++++++++++++
5 files changed, 83 insertions(+)
diff --git
a/extensions/jsonpath/deployment/src/main/java/org/apache/camel/quarkus/component/json/path/deployment/JsonPathProcessor.java
b/extensions/jsonpath/deployment/src/main/java/org/apache/camel/quarkus/component/json/path/deployment/JsonPathProcessor.java
index efc88ec..5e68144 100644
---
a/extensions/jsonpath/deployment/src/main/java/org/apache/camel/quarkus/component/json/path/deployment/JsonPathProcessor.java
+++
b/extensions/jsonpath/deployment/src/main/java/org/apache/camel/quarkus/component/json/path/deployment/JsonPathProcessor.java
@@ -24,6 +24,7 @@ import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import org.apache.camel.jsonpath.JsonPath;
import org.apache.camel.jsonpath.JsonPathAnnotationExpressionFactory;
+import org.apache.camel.jsonpath.jackson.JacksonJsonAdapter;
class JsonPathProcessor {
@@ -39,6 +40,7 @@ class JsonPathProcessor {
List<ReflectiveClassBuildItem> reflectiveClassBuildItems = new
ArrayList<>();
reflectiveClassBuildItems.add(new ReflectiveClassBuildItem(false,
false, JsonPathAnnotationExpressionFactory.class));
reflectiveClassBuildItems.add(new ReflectiveClassBuildItem(true,
false, JsonPath.class));
+ reflectiveClassBuildItems.add(new ReflectiveClassBuildItem(false,
false, JacksonJsonAdapter.class));
return reflectiveClassBuildItems;
}
diff --git
a/integration-tests/jsonpath/src/main/java/org/apache/camel/quarkus/component/json/path/it/JsonPathResource.java
b/integration-tests/jsonpath/src/main/java/org/apache/camel/quarkus/component/json/path/it/JsonPathResource.java
index f1e0caf2..c235593 100644
---
a/integration-tests/jsonpath/src/main/java/org/apache/camel/quarkus/component/json/path/it/JsonPathResource.java
+++
b/integration-tests/jsonpath/src/main/java/org/apache/camel/quarkus/component/json/path/it/JsonPathResource.java
@@ -18,6 +18,7 @@ package org.apache.camel.quarkus.component.json.path.it;
import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -47,6 +48,10 @@ public class JsonPathResource {
private static final Logger LOG = Logger.getLogger(JsonPathResource.class);
+ private static final String WRITE_AS_STRING_TEST_DATA =
"{\"testjson\":{\"users\":[{\"name\":\"Jan\",\"age\":28},{\"age\":10},{\"name\":\"Tom\",\"age\":50}],\"boolean\":true,\"color\":\"gold\","
+ +
"\"null\":null,\"number\":123,\"object\":{\"objectX\":\"myObjectX\",\"objectY\":\"secondbestobject\","
+ +
"\"subObject\":{\"obj1\":\"obj1desc\"}},\"string\":\"HelloWorld\"}}";
+
@Inject
CamelContext context;
@@ -142,4 +147,20 @@ public class JsonPathResource {
}
}
}
+
+ @Path("/splitInputJsonThenWriteAsStringShouldSucceed")
+ @GET
+ public void splitInputJsonThenWriteAsStringShouldSucceed() throws
InterruptedException {
+ LOG.debugf("Split input json and then use jsonpath writeAsString");
+
+ MockEndpoint mockJsonpathWriteAsString =
context.getEndpoint("mock:jsonpathWriteAsString", MockEndpoint.class);
+ mockJsonpathWriteAsString.expectedMessageCount(3);
+ List<String> expectedBodies = new ArrayList<>();
+ expectedBodies.add("{\"name\":\"Jan\",\"age\":28}");
+ expectedBodies.add("{\"age\":10}");
+ expectedBodies.add("{\"name\":\"Tom\",\"age\":50}");
+ mockJsonpathWriteAsString.expectedBodiesReceived(expectedBodies);
+ producerTemplate.requestBody("direct:splitInputJsonThenWriteAsString",
WRITE_AS_STRING_TEST_DATA, String.class);
+ mockJsonpathWriteAsString.assertIsSatisfied();
+ }
}
diff --git
a/integration-tests/jsonpath/src/main/java/org/apache/camel/quarkus/component/json/path/it/JsonPathTestRoute.java
b/integration-tests/jsonpath/src/main/java/org/apache/camel/quarkus/component/json/path/it/JsonPathTestRoute.java
index 549512a..31bfa7b 100644
---
a/integration-tests/jsonpath/src/main/java/org/apache/camel/quarkus/component/json/path/it/JsonPathTestRoute.java
+++
b/integration-tests/jsonpath/src/main/java/org/apache/camel/quarkus/component/json/path/it/JsonPathTestRoute.java
@@ -46,6 +46,9 @@ public class JsonPathTestRoute extends RouteBuilder {
.to("mock:setHeader");
from("direct:getAuthorsFromJsonStream").transform().jsonpath("$.store.book[*].title");
+
+ from("direct:splitInputJsonThenWriteAsString").split()
+
.jsonpathWriteAsString("$.testjson.users").to("mock:jsonpathWriteAsString");
}
@RegisterForReflection
diff --git
a/integration-tests/jsonpath/src/test/java/org/apache/camel/quarkus/component/json/path/it/JsonPathWriteAsStringIT.java
b/integration-tests/jsonpath/src/test/java/org/apache/camel/quarkus/component/json/path/it/JsonPathWriteAsStringIT.java
new file mode 100644
index 0000000..73ea9d3
--- /dev/null
+++
b/integration-tests/jsonpath/src/test/java/org/apache/camel/quarkus/component/json/path/it/JsonPathWriteAsStringIT.java
@@ -0,0 +1,24 @@
+/*
+ * 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.json.path.it;
+
+import io.quarkus.test.junit.NativeImageTest;
+
+@NativeImageTest
+class JsonPathWriteAsStringIT extends JsonPathWriteAsStringTest {
+
+}
diff --git
a/integration-tests/jsonpath/src/test/java/org/apache/camel/quarkus/component/json/path/it/JsonPathWriteAsStringTest.java
b/integration-tests/jsonpath/src/test/java/org/apache/camel/quarkus/component/json/path/it/JsonPathWriteAsStringTest.java
new file mode 100644
index 0000000..e6d5ab0
--- /dev/null
+++
b/integration-tests/jsonpath/src/test/java/org/apache/camel/quarkus/component/json/path/it/JsonPathWriteAsStringTest.java
@@ -0,0 +1,33 @@
+/*
+ * 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.json.path.it;
+
+import io.quarkus.test.junit.QuarkusTest;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.get;
+
+@QuarkusTest
+class JsonPathWriteAsStringTest {
+
+ @Test
+ public void splitInputJsonThenWriteAsStringShouldSucceed() {
+ get("/jsonpath/splitInputJsonThenWriteAsStringShouldSucceed")
+ .then()
+ .statusCode(204);
+ }
+}