You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by mt...@apache.org on 2023/04/29 20:04:35 UTC
[nifi] branch main updated: NIFI-11502 - Upgrade json-path to 2.8.0 NIFI-11502 fixing unit tests NIFI-11502 review
This is an automated email from the ASF dual-hosted git repository.
mthomsen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new 7fb2468f4b NIFI-11502 - Upgrade json-path to 2.8.0 NIFI-11502 fixing unit tests NIFI-11502 review
7fb2468f4b is described below
commit 7fb2468f4b7cef34fe9a8f6fee46eec0a362e18a
Author: Pierre Villard <pi...@gmail.com>
AuthorDate: Fri Apr 28 20:11:06 2023 +0300
NIFI-11502 - Upgrade json-path to 2.8.0
NIFI-11502 fixing unit tests
NIFI-11502 review
This closes #7208
Signed-off-by: Mike Thomsen <mt...@apache.org>
---
nifi-commons/nifi-expression-language/pom.xml | 2 +-
.../language/evaluation/functions/JsonPathDeleteEvaluator.java | 10 ++++++++++
.../language/evaluation/functions/JsonPathUpdateEvaluator.java | 7 +++++++
.../nifi-elasticsearch-client-service/pom.xml | 2 +-
.../nifi-elasticsearch-restapi-processors/pom.xml | 2 +-
.../nifi-record-utils/nifi-json-record-utils/pom.xml | 2 +-
nifi-nar-bundles/nifi-standard-bundle/pom.xml | 2 +-
7 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/nifi-commons/nifi-expression-language/pom.xml b/nifi-commons/nifi-expression-language/pom.xml
index 96fe0316cc..4c773d1ad3 100644
--- a/nifi-commons/nifi-expression-language/pom.xml
+++ b/nifi-commons/nifi-expression-language/pom.xml
@@ -116,7 +116,7 @@
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
- <version>2.6.0</version>
+ <version>2.8.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
diff --git a/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/functions/JsonPathDeleteEvaluator.java b/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/functions/JsonPathDeleteEvaluator.java
index 9ecb77c5f4..960a11273a 100644
--- a/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/functions/JsonPathDeleteEvaluator.java
+++ b/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/functions/JsonPathDeleteEvaluator.java
@@ -20,15 +20,20 @@ import org.apache.nifi.attribute.expression.language.EvaluationContext;
import org.apache.nifi.attribute.expression.language.evaluation.Evaluator;
import org.apache.nifi.attribute.expression.language.evaluation.QueryResult;
import org.apache.nifi.attribute.expression.language.evaluation.StringQueryResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
+import com.jayway.jsonpath.PathNotFoundException;
/**
* JsonPathDeleteEvaluator allows delete elements at the specified path
*/
public class JsonPathDeleteEvaluator extends JsonPathBaseEvaluator {
+ private static final Logger LOGGER = LoggerFactory.getLogger(JsonPathDeleteEvaluator.class);
+
public JsonPathDeleteEvaluator(final Evaluator<String> subject, final Evaluator<String> jsonPathExp) {
super(subject, jsonPathExp);
}
@@ -42,6 +47,11 @@ public class JsonPathDeleteEvaluator extends JsonPathBaseEvaluator {
String result = null;
try {
result = documentContext.delete(compiledJsonPath).jsonString();
+ } catch (PathNotFoundException pnf) {
+ // it is valid for a path not to be found, keys may not be there
+ // do not spam the error log for this, instead we can log debug if enabled
+ LOGGER.debug("JSON Path not found: {}", compiledJsonPath.getPath(), pnf);
+ result = documentContext.jsonString();
} catch (Exception e) {
// assume the path did not match anything in the document
return EMPTY_RESULT;
diff --git a/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/functions/JsonPathUpdateEvaluator.java b/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/functions/JsonPathUpdateEvaluator.java
index 34310ddb91..6ea8d7d79a 100644
--- a/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/functions/JsonPathUpdateEvaluator.java
+++ b/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/functions/JsonPathUpdateEvaluator.java
@@ -18,6 +18,8 @@ package org.apache.nifi.attribute.expression.language.evaluation.functions;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
+import com.jayway.jsonpath.PathNotFoundException;
+
import org.apache.commons.lang3.NotImplementedException;
import org.apache.nifi.attribute.expression.language.EvaluationContext;
import org.apache.nifi.attribute.expression.language.evaluation.Evaluator;
@@ -52,6 +54,11 @@ public abstract class JsonPathUpdateEvaluator extends JsonPathBaseEvaluator {
String result;
try {
result = updateAttribute(documentContext, compiledJsonPath, value).jsonString();
+ } catch (PathNotFoundException pnf) {
+ // it is valid for a path not to be found, keys may not be there
+ // do not spam the error log for this, instead we can log debug if enabled
+ LOGGER.debug("JSON Path not found: {}", compiledJsonPath.getPath(), pnf);
+ result = documentContext.jsonString();
} catch (Exception e) {
LOGGER.error("Failed to update attribute " + e.getLocalizedMessage(), e);
// assume the path did not match anything in the document
diff --git a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/pom.xml b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/pom.xml
index 3cc3f98bef..d49b6ed894 100644
--- a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/pom.xml
+++ b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/pom.xml
@@ -121,7 +121,7 @@
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
- <version>2.7.0</version>
+ <version>2.8.0</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
diff --git a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/pom.xml b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/pom.xml
index 0dbfbe7e18..cfe8d9d4b5 100644
--- a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/pom.xml
+++ b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/pom.xml
@@ -89,7 +89,7 @@ language governing permissions and limitations under the License. -->
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
- <version>2.7.0</version>
+ <version>2.8.0</version>
<scope>compile</scope>
</dependency>
diff --git a/nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-json-record-utils/pom.xml b/nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-json-record-utils/pom.xml
index 1880da44d7..6ce68e83cd 100755
--- a/nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-json-record-utils/pom.xml
+++ b/nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-json-record-utils/pom.xml
@@ -37,7 +37,7 @@
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
- <version>2.6.0</version>
+ <version>2.8.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
diff --git a/nifi-nar-bundles/nifi-standard-bundle/pom.xml b/nifi-nar-bundles/nifi-standard-bundle/pom.xml
index 3f92982797..641051801f 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/pom.xml
+++ b/nifi-nar-bundles/nifi-standard-bundle/pom.xml
@@ -184,7 +184,7 @@
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
- <version>2.6.0</version>
+ <version>2.8.0</version>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>