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

Commit

Permalink
do not stringify null results in json jq task (#3225)
Browse files Browse the repository at this point in the history
  • Loading branch information
apanicker-nflx authored Sep 8, 2022
1 parent 6413a12 commit a2a64e6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
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"));
}
}

0 comments on commit a2a64e6

Please sign in to comment.