Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Handle null results in json jq task script evaluation #3225

Merged
merged 1 commit into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public void stringResultShouldBeCorrectlyExtracted() {
assertEquals("CREATE", result);
}

@SuppressWarnings("unchecked")
@Test
public void listResultShouldBeCorrectlyExtracted() throws JsonProcessingException {
final JsonJqTransform jsonJqTransform = new JsonJqTransform(objectMapper);
Expand All @@ -170,4 +171,19 @@ public void listResultShouldBeCorrectlyExtracted() throws JsonProcessingExceptio
List<Object> result = (List<Object>) 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<String, Object> 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"));
}
}