Repository: nifi Updated Branches: refs/heads/develop 13042dc2e -> b51433e97
NIFI-726 Providing updated documentation on how the return type property is interpreted for EvaluateJsonPath Project: http://git-wip-us.apache.org/repos/asf/nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/b51433e9 Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/b51433e9 Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/b51433e9 Branch: refs/heads/develop Commit: b51433e97c5b51b0e8f35450c3e4265fd747f51a Parents: 13042dc Author: Aldrin Piri <aldrin at apache dot org> Authored: Wed Aug 12 17:10:57 2015 -0400 Committer: Aldrin Piri <aldrin at apache dot org> Committed: Wed Aug 12 23:29:54 2015 -0400 ---------------------------------------------------------------------- .../nifi/processors/standard/EvaluateJsonPath.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nifi/blob/b51433e9/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/EvaluateJsonPath.java ---------------------------------------------------------------------- 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 b4ddc16..ad3120c 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 @@ -66,6 +66,9 @@ import java.util.concurrent.ConcurrentMap; + "JsonPaths are entered by adding user-defined properties; the name of the property maps to the Attribute Name " + "into which the result will be placed (if the Destination is flowfile-attribute; otherwise, the property name is ignored). " + "The value of the property must be a valid JsonPath expression. " + + "A Return Type of 'auto-detect' will make a determination based off the configured destination. " + + "When 'Destination' is set to 'flowfile-attribute,' a return type of 'scalar' will be used. " + + "When 'Destination' is set to 'flowfile-content,' a return type of 'JSON' will be used." + "If the JsonPath evaluates to a JSON array or JSON object and the Return Type is set to 'scalar' the FlowFile will be unmodified and will be routed to failure. " + "A Return Type of JSON can return scalar values if the provided JsonPath evaluates to the specified value and will be routed as a match." + "If Destination is 'flowfile-content' and the JsonPath does not evaluate to a defined path, the FlowFile will be routed to 'unmatched' without having its contents modified. " @@ -99,7 +102,7 @@ public class EvaluateJsonPath extends AbstractJsonPathProcessor { public static final PropertyDescriptor RETURN_TYPE = new PropertyDescriptor.Builder() .name("Return Type").description("Indicates the desired return type of the JSON Path expressions. Selecting 'auto-detect' will set the return type to 'json' " - + "for a Destination of 'flowfile-content', and 'string' for a Destination of 'flowfile-attribute'.") + + "for a Destination of 'flowfile-content', and 'scalar' for a Destination of 'flowfile-attribute'.") .required(true) .allowableValues(RETURN_TYPE_AUTO, RETURN_TYPE_JSON, RETURN_TYPE_SCALAR) .defaultValue(RETURN_TYPE_AUTO) @@ -224,7 +227,7 @@ public class EvaluateJsonPath extends AbstractJsonPathProcessor { } @Override - public void onTrigger(ProcessContext processContext, final ProcessSession processSession) throws ProcessException { + public void onTrigger(final ProcessContext processContext, final ProcessSession processSession) throws ProcessException { FlowFile flowFile = processSession.get(); if (flowFile == null) { @@ -266,13 +269,13 @@ public class EvaluateJsonPath extends AbstractJsonPathProcessor { for (final Map.Entry<String, JsonPath> attributeJsonPathEntry : attributeToJsonPathMap.entrySet()) { - String jsonPathAttrKey = attributeJsonPathEntry.getKey(); - JsonPath jsonPathExp = attributeJsonPathEntry.getValue(); + final String jsonPathAttrKey = attributeJsonPathEntry.getKey(); + final JsonPath jsonPathExp = attributeJsonPathEntry.getValue(); final String pathNotFound = processContext.getProperty(PATH_NOT_FOUND).getValue(); final ObjectHolder<Object> resultHolder = new ObjectHolder<>(null); try { - Object result = documentContext.read(jsonPathExp); + final Object result = documentContext.read(jsonPathExp); if (returnType.equals(RETURN_TYPE_SCALAR) && !isJsonScalar(result)) { logger.error("Unable to return a scalar value for the expression {} for FlowFile {}. Evaluated value was {}. Transferring to {}.", new Object[]{jsonPathExp.getPath(), flowFile.getId(), result.toString(), REL_FAILURE.getName()});
