This is an automated email from the ASF dual-hosted git repository.
exceptionfactory 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 74a9c94d3d8 NIFI-16190 Added support for filtering out null results
for JSON lines in JSLTTransformJSON (#11850)
74a9c94d3d8 is described below
commit 74a9c94d3d83e1e70b9441f13393ee46c5ed7818
Author: dan-s1 <[email protected]>
AuthorDate: Fri Oct 30 14:04:20 2026 -0400
NIFI-16190 Added support for filtering out null results for JSON lines in
JSLTTransformJSON (#11850)
Signed-off-by: David Handermann <[email protected]>
---
.../nifi/processors/jslt/JSLTTransformJSON.java | 8 +++++-
.../processors/jslt/TestJSLTTransformJSON.java | 31 ++++++++++++++++++++++
2 files changed, 38 insertions(+), 1 deletion(-)
diff --git
a/nifi-extension-bundles/nifi-jslt-bundle/nifi-jslt-processors/src/main/java/org/apache/nifi/processors/jslt/JSLTTransformJSON.java
b/nifi-extension-bundles/nifi-jslt-bundle/nifi-jslt-processors/src/main/java/org/apache/nifi/processors/jslt/JSLTTransformJSON.java
index 42b3fa63483..9916bf64e14 100644
---
a/nifi-extension-bundles/nifi-jslt-bundle/nifi-jslt-processors/src/main/java/org/apache/nifi/processors/jslt/JSLTTransformJSON.java
+++
b/nifi-extension-bundles/nifi-jslt-bundle/nifi-jslt-processors/src/main/java/org/apache/nifi/processors/jslt/JSLTTransformJSON.java
@@ -476,14 +476,20 @@ public class JSLTTransformJSON extends AbstractProcessor {
try (final BufferedReader reader = new BufferedReader(new
InputStreamReader(inputStream, StandardCharsets.UTF_8));
final JsonGenerator jsonGenerator =
writer.createGenerator(outputStream)) {
String line;
+ int lines = 0;
while ((line = reader.readLine()) != null) {
+ lines++;
if (line.isBlank()) {
continue;
}
final JsonNode jsonNode =
JSON_OBJECT_MAPPER.readTree(line);
final JsonNode transformedJson =
jsltExpression.apply(jsonNode);
- jsonGenerator.writeObject(transformedJson);
+ if (transformedJson == null || transformedJson.isNull()) {
+ getLogger().debug("JSLT Transform resulted in no data
on line {}", lines);
+ } else {
+ jsonGenerator.writeObject(transformedJson);
+ }
}
}
});
diff --git
a/nifi-extension-bundles/nifi-jslt-bundle/nifi-jslt-processors/src/test/java/org/apache/nifi/processors/jslt/TestJSLTTransformJSON.java
b/nifi-extension-bundles/nifi-jslt-bundle/nifi-jslt-processors/src/test/java/org/apache/nifi/processors/jslt/TestJSLTTransformJSON.java
index c0c10280dd2..4cba1d3e53a 100644
---
a/nifi-extension-bundles/nifi-jslt-bundle/nifi-jslt-processors/src/test/java/org/apache/nifi/processors/jslt/TestJSLTTransformJSON.java
+++
b/nifi-extension-bundles/nifi-jslt-bundle/nifi-jslt-processors/src/test/java/org/apache/nifi/processors/jslt/TestJSLTTransformJSON.java
@@ -297,6 +297,37 @@ public class TestJSLTTransformJSON {
);
}
+ @Test
+ public void testJsonLinesSkipsNullTransformationResults() {
+ final String input = """
+ {"id":1,"event":"deposit","amount":10}
+ {"id":2,"event":"payment_updated","amount":10}
+ {"id":3,"event":"deposit","amount":25}
+ {"id":4,"event":"payment_updated","amount":25}
+ {"id":5,"event":"deposit","amount":40}
+ """;
+
+ runner.setProperty(JSLTTransformJSON.INPUT_FORMAT,
JSLTTransformJSON.InputFormat.JSON_LINES);
+ runner.setProperty(JSLTTransformJSON.JSLT_TRANSFORM,
+ """
+ if (.event == "deposit") {"id": .id, "amount":
.amount}""");
+
+ runner.enqueue(input);
+ runner.run();
+
+ runner.assertTransferCount(JSLTTransformJSON.REL_SUCCESS, 1);
+ runner.assertTransferCount(JSLTTransformJSON.REL_FAILURE, 0);
+
+ final MockFlowFile flowFile =
runner.getFlowFilesForRelationship(JSLTTransformJSON.REL_SUCCESS).getFirst();
+ final String expectedJson = """
+ {"id":1,"amount":10}
+ {"id":3,"amount":25}
+ {"id":5,"amount":40}
+ """.trim();
+
+ assertEquals(expectedJson, flowFile.getContent());
+ }
+
// This test verifies transformCache cleanup does not throw an exception
@Test
public void testShutdown() {