This is an automated email from the ASF dual-hosted git repository.
mthomsen pushed a commit to branch support/nifi-1.x
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/support/nifi-1.x by this push:
new c9cd18f6d5 NIFI-11502 - Upgrade json-path to 2.8.0 NIFI-11502 fixing
unit tests NIFI-11502 review
c9cd18f6d5 is described below
commit c9cd18f6d5128033d1b62881942a621a114b9875
Author: Pierre Villard <[email protected]>
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 <[email protected]>
---
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 9396a7c7d4..2ec0b60b28 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 f9bf1d05a3..a232c261d5 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 715cae4d7f..10bb8f580b 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 fba4193385..4ff557ad53 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
@@ -32,7 +32,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 7dd0219fba..3257b59c65 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/pom.xml
+++ b/nifi-nar-bundles/nifi-standard-bundle/pom.xml
@@ -195,7 +195,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>