diff --git a/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/json/JsonSchemaGenerator.java b/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/json/JsonSchemaGenerator.java index aac1aad4fbb..e101099eaf3 100644 --- a/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/json/JsonSchemaGenerator.java +++ b/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/json/JsonSchemaGenerator.java @@ -125,7 +125,7 @@ public Collection generate() throws IOException { if (merged == null) { merged = read; } else { - JsonUtils.merge(read, merged); + merged = (ObjectNode) JsonUtils.merge(read, merged); } } try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { diff --git a/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/json/JsonUtils.java b/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/json/JsonUtils.java index 7c3bba18877..624974f5f30 100644 --- a/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/json/JsonUtils.java +++ b/kogito-codegen-modules/kogito-codegen-processes/src/main/java/org/kie/kogito/codegen/json/JsonUtils.java @@ -34,8 +34,8 @@ private JsonUtils() { * @param src JsonNode to be merged * @param target JsonNode to merge to */ - public static void merge(JsonNode src, JsonNode target) { - MergeUtils.merge(src, target, true); + public static JsonNode merge(JsonNode src, JsonNode target) { + return MergeUtils.merge(src, target, true); } } diff --git a/kogito-codegen-modules/kogito-codegen-processes/src/test/java/org/kie/kogito/codegen/json/JsonUtilsTest.java b/kogito-codegen-modules/kogito-codegen-processes/src/test/java/org/kie/kogito/codegen/json/JsonUtilsTest.java index 69b4124c684..f1677616f88 100644 --- a/kogito-codegen-modules/kogito-codegen-processes/src/test/java/org/kie/kogito/codegen/json/JsonUtilsTest.java +++ b/kogito-codegen-modules/kogito-codegen-processes/src/test/java/org/kie/kogito/codegen/json/JsonUtilsTest.java @@ -42,11 +42,11 @@ public void testFullMerge() { JsonNode node5 = createJson(mapper, mapper.createObjectNode().put("string", "javier")); JsonNode result = mapper.createObjectNode(); - JsonUtils.merge(node1, result); - JsonUtils.merge(node2, result); - JsonUtils.merge(node3, result); - JsonUtils.merge(node4, result); - JsonUtils.merge(node5, result); + result = JsonUtils.merge(node1, result); + result = JsonUtils.merge(node2, result); + result = JsonUtils.merge(node3, result); + result = JsonUtils.merge(node4, result); + result = JsonUtils.merge(node5, result); assertThat(result.size()).isOne(); JsonNode merged = result.get("merged"); @@ -73,7 +73,7 @@ public void testArrayIntoObjectMerge() { JsonNode src = createJson(mapper, createJson(mapper, "property", Arrays.asList(1, 2, 3))); JsonNode target = createJson(mapper, mapper.createObjectNode().put("property", 4)); - JsonUtils.merge(src, target); + target = JsonUtils.merge(src, target); assertThat(target.size()).isOne(); JsonNode merged = target.get("merged"); @@ -95,7 +95,7 @@ public void testArrayIntoNewPropertyMerge() { JsonNode src = createJson(mapper, createJson(mapper, "property", Arrays.asList(1, 2, 3))); JsonNode target = createJson(mapper, mapper.createObjectNode()); - JsonUtils.merge(src, target); + target = JsonUtils.merge(src, target); assertThat(target.size()).isOne(); JsonNode merged = target.get("merged"); diff --git a/kogito-serverless-workflow/kogito-serverless-workflow-executor-core/src/test/java/org/kie/kogito/serverless/workflow/executor/StaticFluentWorkflowApplicationTest.java b/kogito-serverless-workflow/kogito-serverless-workflow-executor-core/src/test/java/org/kie/kogito/serverless/workflow/executor/StaticFluentWorkflowApplicationTest.java index 81de083a09a..dcd49e1bc9a 100644 --- a/kogito-serverless-workflow/kogito-serverless-workflow-executor-core/src/test/java/org/kie/kogito/serverless/workflow/executor/StaticFluentWorkflowApplicationTest.java +++ b/kogito-serverless-workflow/kogito-serverless-workflow-executor-core/src/test/java/org/kie/kogito/serverless/workflow/executor/StaticFluentWorkflowApplicationTest.java @@ -77,7 +77,7 @@ public void afterProcessCompleted(ProcessCompletedEvent event) { } }).build()) { Workflow workflow = workflow("HelloWorld").start(inject(new TextNode(GREETING_STRING))).end().build(); - assertThat(application.execute(workflow, Collections.emptyMap()).getWorkflowdata()).contains(new TextNode(GREETING_STRING)); + assertThat(application.execute(workflow, Collections.emptyMap()).getWorkflowdata().asText()).isEqualTo(GREETING_STRING); assertThat(completed.get()).isTrue(); } } @@ -222,7 +222,7 @@ void testConstantConcatenation() { try (StaticWorkflowApplication application = StaticWorkflowApplication.create()) { Workflow workflow = workflow("PlayingWithExpression").constant("name", "Javierito").function(expr(INTERPOLATION, "\"My name is \"+$CONST.name")) .start(operation().action(call(INTERPOLATION))).end().build(); - assertThat(application.execute(workflow, Collections.emptyMap()).getWorkflowdata().get("response").asText()).isEqualTo("My name is Javierito"); + assertThat(application.execute(workflow, Collections.emptyMap()).getWorkflowdata().asText()).isEqualTo("My name is Javierito"); } } @@ -280,7 +280,7 @@ void testConstantInterpolation() { try (StaticWorkflowApplication application = StaticWorkflowApplication.create()) { Workflow workflow = workflow("PlayingWithExpression").constant("name", "Javierito").function(expr(INTERPOLATION, "\"My name is \\($CONST.name)\"")) .start(operation().action(call(INTERPOLATION))).end().build(); - assertThat(application.execute(workflow, Collections.emptyMap()).getWorkflowdata().get("response").asText()).isEqualTo("My name is Javierito"); + assertThat(application.execute(workflow, Collections.emptyMap()).getWorkflowdata().asText()).isEqualTo("My name is Javierito"); } } } diff --git a/kogito-serverless-workflow/kogito-serverless-workflow-executor-core/src/test/java/org/kie/kogito/serverless/workflow/executor/StaticWorkflowApplicationTest.java b/kogito-serverless-workflow/kogito-serverless-workflow-executor-core/src/test/java/org/kie/kogito/serverless/workflow/executor/StaticWorkflowApplicationTest.java index 5da4db34d09..4309f18156c 100644 --- a/kogito-serverless-workflow/kogito-serverless-workflow-executor-core/src/test/java/org/kie/kogito/serverless/workflow/executor/StaticWorkflowApplicationTest.java +++ b/kogito-serverless-workflow/kogito-serverless-workflow-executor-core/src/test/java/org/kie/kogito/serverless/workflow/executor/StaticWorkflowApplicationTest.java @@ -62,7 +62,7 @@ class StaticWorkflowApplicationTest { void helloWorld() { Workflow workflow = helloWorldDef(); try (StaticWorkflowApplication application = StaticWorkflowApplication.create()) { - assertThat(application.execute(workflow, Collections.emptyMap()).getWorkflowdata()).contains(new TextNode(GREETING_STRING)); + assertThat(application.execute(workflow, Collections.emptyMap()).getWorkflowdata().asText()).isEqualTo(GREETING_STRING); } } @@ -74,7 +74,7 @@ void helloWorldFile() throws IOException { CharArrayReader reader = new CharArrayReader(writer.toCharArray()); workflow = getWorkflow(reader, WorkflowFormat.JSON); try (StaticWorkflowApplication application = StaticWorkflowApplication.create()) { - assertThat(application.execute(workflow, Collections.emptyMap()).getWorkflowdata()).contains(new TextNode(GREETING_STRING)); + assertThat(application.execute(workflow, Collections.emptyMap()).getWorkflowdata().asText()).isEqualTo(GREETING_STRING); } } diff --git a/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/actions/MergeAction.java b/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/actions/MergeAction.java index e4b5c396658..62551321e27 100644 --- a/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/actions/MergeAction.java +++ b/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/actions/MergeAction.java @@ -34,6 +34,6 @@ public MergeAction(String inputName, String outputName) { @Override public void execute(KogitoProcessContext context) throws Exception { - MergeUtils.merge(ActionUtils.getJsonNode(context, inputName), ActionUtils.getJsonNode(context, outputName)); + context.setVariable(outputName, MergeUtils.merge(ActionUtils.getJsonNode(context, inputName), ActionUtils.getJsonNode(context, outputName))); } } diff --git a/kogito-workitems/kogito-jackson-utils/src/main/java/org/kie/kogito/jackson/utils/MergeUtils.java b/kogito-workitems/kogito-jackson-utils/src/main/java/org/kie/kogito/jackson/utils/MergeUtils.java index 1f946002499..1ddcf12c8c0 100644 --- a/kogito-workitems/kogito-jackson-utils/src/main/java/org/kie/kogito/jackson/utils/MergeUtils.java +++ b/kogito-workitems/kogito-jackson-utils/src/main/java/org/kie/kogito/jackson/utils/MergeUtils.java @@ -39,7 +39,7 @@ public static JsonNode merge(JsonNode src, JsonNode target) { } public static JsonNode merge(JsonNode src, JsonNode target, boolean mergeArray) { - if (target == null || target.isNull()) { + if (target == null || target.isNull() || target.isObject() && target.isEmpty() && src != null && !src.isNull()) { return src; } else if (target.isArray()) { return mergeArray(src, (ArrayNode) target, mergeArray); diff --git a/kogito-workitems/kogito-jackson-utils/src/test/java/org/kie/kogito/jackson/utils/MergeUtilsTest.java b/kogito-workitems/kogito-jackson-utils/src/test/java/org/kie/kogito/jackson/utils/MergeUtilsTest.java index d9d789dadd5..c7f034393ed 100644 --- a/kogito-workitems/kogito-jackson-utils/src/test/java/org/kie/kogito/jackson/utils/MergeUtilsTest.java +++ b/kogito-workitems/kogito-jackson-utils/src/test/java/org/kie/kogito/jackson/utils/MergeUtilsTest.java @@ -52,13 +52,13 @@ void testTargetIntSrcArray() { @Test void testTargetObjectSrcInt() { - assertThat(JsonObjectUtils.toJavaValue(MergeUtils.merge(new IntNode(3), ObjectMapperFactory.get().createObjectNode(), false))).isEqualTo(Collections.singletonMap("response", 3)); + assertThat(JsonObjectUtils.toJavaValue(MergeUtils.merge(new IntNode(3), ObjectMapperFactory.get().createObjectNode(), false))).isEqualTo(3); } @Test void testTargetObjectSrcArray() { assertThat(JsonObjectUtils.toJavaValue(MergeUtils.merge(ObjectMapperFactory.get().createArrayNode().add(1).add(2).add(3), ObjectMapperFactory.get().createObjectNode(), false))) - .isEqualTo(Collections.singletonMap("response", Arrays.asList(1, 2, 3))); + .isEqualTo(Arrays.asList(1, 2, 3)); } @Test