diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateJsonPath.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateJsonPath.java index 3a64a34a42..d79a6dec5b 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateJsonPath.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateJsonPath.java @@ -215,7 +215,7 @@ public class EvaluateJsonPath extends AbstractProcessor { } } - final String resultRepresentation = getResultRepresentation(resultHolder.get()); + final String resultRepresentation = JsonUtils.getResultRepresentation(resultHolder.get()); switch (destination) { case DESTINATION_ATTRIBUTE: jsonPathResults.put(jsonPathAttrKey, resultRepresentation); @@ -237,12 +237,4 @@ public class EvaluateJsonPath extends AbstractProcessor { } } - private static String getResultRepresentation(Object jsonPathResult) { - if (JsonUtils.isJsonScalar(jsonPathResult)) { - return jsonPathResult.toString(); - } - return JsonUtils.JSON_PROVIDER.toJson(jsonPathResult); - } - - } diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/SplitJson.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/SplitJson.java index c2b520cbe4..78e1b2a950 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/SplitJson.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/SplitJson.java @@ -129,12 +129,7 @@ public class SplitJson extends AbstractProcessor { split = processSession.write(split, new OutputStreamCallback() { @Override public void process(OutputStream out) throws IOException { - String resultSegmentContent; - if (JsonUtils.isJsonScalar(resultSegment)) { - resultSegmentContent = resultSegment.toString(); - } else { - resultSegmentContent = JsonUtils.JSON_PROVIDER.toJson(resultSegment); - } + String resultSegmentContent = JsonUtils.getResultRepresentation(resultSegment); out.write(resultSegmentContent.getBytes(StandardCharsets.UTF_8)); } }); diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/JsonUtils.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/JsonUtils.java index 6f97207daa..2174c1ef7e 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/JsonUtils.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/JsonUtils.java @@ -46,7 +46,7 @@ import java.util.Map; */ public class JsonUtils { - public static final JsonProvider JSON_PROVIDER = Configuration.defaultConfiguration().jsonProvider(); + static final JsonProvider JSON_PROVIDER = Configuration.defaultConfiguration().jsonProvider(); public static final Validator JSON_PATH_VALIDATOR = new Validator() { @Override @@ -116,4 +116,12 @@ public class JsonUtils { return !(obj instanceof Map || obj instanceof List); } + + public static String getResultRepresentation(Object jsonPathResult) { + if (JsonUtils.isJsonScalar(jsonPathResult)) { + return jsonPathResult.toString(); + } + return JSON_PROVIDER.toJson(jsonPathResult); + } + }