diff --git a/json-jq-task/src/main/java/com/netflix/conductor/tasks/json/JsonJqTransform.java b/json-jq-task/src/main/java/com/netflix/conductor/tasks/json/JsonJqTransform.java index fc79d4831d..5bd28b0f39 100644 --- a/json-jq-task/src/main/java/com/netflix/conductor/tasks/json/JsonJqTransform.java +++ b/json-jq-task/src/main/java/com/netflix/conductor/tasks/json/JsonJqTransform.java @@ -124,7 +124,9 @@ private String extractFirstValidMessage(final Exception e) { } private Object extractBody(JsonNode node) { - if (node.isObject()) { + if (node.isNull()) { + return null; + } else if (node.isObject()) { return objectMapper.convertValue(node, mapType); } else if (node.isArray()) { return objectMapper.convertValue(node, listType); diff --git a/json-jq-task/src/test/java/com/netflix/conductor/tasks/json/JsonJqTransformTest.java b/json-jq-task/src/test/java/com/netflix/conductor/tasks/json/JsonJqTransformTest.java index 3f12d48ec6..815993f773 100644 --- a/json-jq-task/src/test/java/com/netflix/conductor/tasks/json/JsonJqTransformTest.java +++ b/json-jq-task/src/test/java/com/netflix/conductor/tasks/json/JsonJqTransformTest.java @@ -148,6 +148,7 @@ public void stringResultShouldBeCorrectlyExtracted() { assertEquals("CREATE", result); } + @SuppressWarnings("unchecked") @Test public void listResultShouldBeCorrectlyExtracted() throws JsonProcessingException { final JsonJqTransform jsonJqTransform = new JsonJqTransform(objectMapper); @@ -170,4 +171,19 @@ public void listResultShouldBeCorrectlyExtracted() throws JsonProcessingExceptio List result = (List) task.getOutputData().get("result"); assertEquals(3, result.size()); } + + @Test + public void nullResultShouldBeCorrectlyExtracted() throws JsonProcessingException { + final JsonJqTransform jsonJqTransform = new JsonJqTransform(objectMapper); + final WorkflowModel workflow = new WorkflowModel(); + final TaskModel task = new TaskModel(); + final Map taskInput = new HashMap<>(); + taskInput.put("queryExpression", "null"); + task.setInputData(taskInput); + + jsonJqTransform.start(workflow, task, null); + + assertNull(task.getOutputData().get("error")); + assertNull(task.getOutputData().get("result")); + } }