mirror of https://github.com/apache/nifi.git
Adding an auto return type for EvaluateJsonPath to match the semantics of the EvaluateXPath processor.
This commit is contained in:
parent
1a746212bf
commit
627bd91fa7
|
@ -61,6 +61,7 @@ public class EvaluateJsonPath extends AbstractProcessor {
|
|||
public static final String DESTINATION_ATTRIBUTE = "flowfile-attribute";
|
||||
public static final String DESTINATION_CONTENT = "flowfile-content";
|
||||
|
||||
public static final String RETURN_TYPE_AUTO = "auto-detect";
|
||||
public static final String RETURN_TYPE_JSON = "json";
|
||||
public static final String RETURN_TYPE_SCALAR = "scalar";
|
||||
|
||||
|
@ -76,8 +77,8 @@ public class EvaluateJsonPath extends AbstractProcessor {
|
|||
.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'.")
|
||||
.required(true)
|
||||
.allowableValues(RETURN_TYPE_JSON, RETURN_TYPE_SCALAR)
|
||||
.defaultValue(RETURN_TYPE_JSON)
|
||||
.allowableValues(RETURN_TYPE_AUTO, RETURN_TYPE_JSON, RETURN_TYPE_SCALAR)
|
||||
.defaultValue(RETURN_TYPE_AUTO)
|
||||
.build();
|
||||
|
||||
public static final Relationship REL_MATCH = new Relationship.Builder().name("matched").description("FlowFiles are routed to this relationship when the JsonPath is successfully evaluated and the FlowFile is modified as a result").build();
|
||||
|
@ -168,7 +169,10 @@ public class EvaluateJsonPath extends AbstractProcessor {
|
|||
}
|
||||
|
||||
final String destination = processContext.getProperty(DESTINATION).getValue();
|
||||
final String returnType = processContext.getProperty(RETURN_TYPE).getValue();
|
||||
String returnType = processContext.getProperty(RETURN_TYPE).getValue();
|
||||
if (returnType.equals(RETURN_TYPE_AUTO)) {
|
||||
returnType = destination.equals(DESTINATION_CONTENT) ? RETURN_TYPE_JSON : RETURN_TYPE_SCALAR;
|
||||
}
|
||||
|
||||
flowFileLoop:
|
||||
for (FlowFile flowFile : flowFiles) {
|
||||
|
|
|
@ -100,6 +100,7 @@ public class TestEvaluateJsonPath {
|
|||
public void testExtractPath_destinationAttributes_twoPaths() throws Exception {
|
||||
final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateJsonPath());
|
||||
testRunner.setProperty(EvaluateJsonPath.DESTINATION, EvaluateJsonPath.DESTINATION_ATTRIBUTE);
|
||||
testRunner.setProperty(EvaluateJsonPath.RETURN_TYPE, EvaluateJsonPath.RETURN_TYPE_JSON);
|
||||
|
||||
String jsonPathIdAttrKey = "evaluatejson.id";
|
||||
String jsonPathNameAttrKey = "evaluatejson.name";
|
||||
|
|
Loading…
Reference in New Issue