You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2024/10/03 04:56:39 UTC
(camel) branch camel-4.4.x updated: CAMEL-21306: camel-jsonpath - Null should be accepted return value (#15812)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-4.4.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.4.x by this push:
new 8c34eb76249 CAMEL-21306: camel-jsonpath - Null should be accepted return value (#15812)
8c34eb76249 is described below
commit 8c34eb76249e096a3e27a2f03d85865590123260
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Oct 3 06:55:36 2024 +0200
CAMEL-21306: camel-jsonpath - Null should be accepted return value (#15812)
---
.../org/apache/camel/jsonpath/JsonPathEngine.java | 6 +-
.../camel/jsonpath/JsonPathNullHeaderTest.java | 64 ++++++++++++++++++++++
2 files changed, 67 insertions(+), 3 deletions(-)
diff --git a/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java b/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java
index afbdc83b699..ebe49dd9eab 100644
--- a/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java
+++ b/components/camel-jsonpath/src/main/java/org/apache/camel/jsonpath/JsonPathEngine.java
@@ -194,15 +194,15 @@ public class JsonPathEngine {
if (json instanceof String) {
LOG.trace("JSonPath: {} is read as String: {}", path, json);
String str = (String) json;
- answer = JsonPath.using(configuration).parse(str).read(path);
+ return JsonPath.using(configuration).parse(str).read(path);
} else if (json instanceof Map) {
LOG.trace("JSonPath: {} is read as Map: {}", path, json);
Map map = (Map) json;
- answer = JsonPath.using(configuration).parse(map).read(path);
+ return JsonPath.using(configuration).parse(map).read(path);
} else if (json instanceof List) {
LOG.trace("JSonPath: {} is read as List: {}", path, json);
List list = (List) json;
- answer = JsonPath.using(configuration).parse(list).read(path);
+ return JsonPath.using(configuration).parse(list).read(path);
} else {
//try to auto convert into inputStream
answer = readWithInputStream(path, exchange);
diff --git a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathNullHeaderTest.java b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathNullHeaderTest.java
new file mode 100644
index 00000000000..9362d89735f
--- /dev/null
+++ b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathNullHeaderTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.jsonpath;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+public class JsonPathNullHeaderTest extends CamelTestSupport {
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:start")
+ .setHeader("foo").jsonpath("$.foo")
+ .to("mock:foo");
+ }
+ };
+ }
+
+ @Test
+ public void testHeaderValue() throws Exception {
+ getMockEndpoint("mock:foo").expectedHeaderReceived("foo", "cheese");
+
+ template.sendBody("direct:start", """
+ {
+ "foo": "cheese"
+ }
+ """);
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+ @Test
+ public void testHeaderNull() throws Exception {
+ getMockEndpoint("mock:foo").expectedHeaderReceived("foo", null);
+
+ template.sendBody("direct:start", """
+ {
+ "foo": null
+ }
+ """);
+
+ MockEndpoint.assertIsSatisfied(context);
+ }
+
+}