diff --git a/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/models/JsonNodeModel.java b/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/models/JsonNodeModel.java index cd8bdb78ebf..0897cc77290 100644 --- a/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/models/JsonNodeModel.java +++ b/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/models/JsonNodeModel.java @@ -50,7 +50,15 @@ public JsonNodeModel(Object workflowdata) { this(null, workflowdata); } + public JsonNodeModel(Object workflowdata, Map additionalProperties) { + this(null, workflowdata, additionalProperties); + } + public JsonNodeModel(String id, Object workflowdata) { + this(id, workflowdata, Collections.emptyMap()); + } + + public JsonNodeModel(String id, Object workflowdata, Map additionalProperties) { this.id = id; if (workflowdata instanceof JsonNode) { this.workflowdata = (JsonNode) workflowdata; @@ -59,6 +67,7 @@ public JsonNodeModel(String id, Object workflowdata) { this.workflowdata = workflowdata == null ? mapper.createObjectNode() : mapper.convertValue(workflowdata, JsonNode.class); } this.input = this.workflowdata.deepCopy(); + this.additionalProperties = additionalProperties == null ? Collections.emptyMap() : additionalProperties; } public String getId() { diff --git a/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/models/JsonNodeModelInput.java b/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/models/JsonNodeModelInput.java index 98adedb04f5..d53aa9ea777 100644 --- a/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/models/JsonNodeModelInput.java +++ b/kogito-serverless-workflow/kogito-serverless-workflow-runtime/src/main/java/org/kie/kogito/serverless/workflow/models/JsonNodeModelInput.java @@ -18,20 +18,23 @@ */ package org.kie.kogito.serverless.workflow.models; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; + import org.kie.kogito.MapInput; import org.kie.kogito.MapInputId; import org.kie.kogito.MapOutput; import org.kie.kogito.MappableToModel; import org.kie.kogito.Model; -import org.kie.kogito.jackson.utils.ObjectMapperFactory; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ObjectNode; public class JsonNodeModelInput implements Model, MapInput, MapInputId, MapOutput, MappableToModel { private Object workflowdata; + private Map additionalProperties; public Object getWorkflowdata() { return workflowdata; @@ -39,16 +42,18 @@ public Object getWorkflowdata() { @JsonAnySetter public void setData(String key, JsonNode value) { - if (workflowdata == null) { - workflowdata = ObjectMapperFactory.listenerAware().createObjectNode(); - } - if (workflowdata instanceof ObjectNode) { - ((ObjectNode) workflowdata).set(key, value); + if (additionalProperties == null) { + additionalProperties = new LinkedHashMap<>(); } + additionalProperties.put(key, value); } @Override public JsonNodeModel toModel() { - return new JsonNodeModel(workflowdata); + if (workflowdata == null) { + workflowdata = additionalProperties; + additionalProperties = Collections.emptyMap(); + } + return new JsonNodeModel(workflowdata, additionalProperties); } } diff --git a/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/test/java/org/kie/kogito/quarkus/workflows/ExpressionRestIT.java b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/test/java/org/kie/kogito/quarkus/workflows/ExpressionRestIT.java index d6d4122929d..5f0b44234a8 100644 --- a/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/test/java/org/kie/kogito/quarkus/workflows/ExpressionRestIT.java +++ b/quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/test/java/org/kie/kogito/quarkus/workflows/ExpressionRestIT.java @@ -38,7 +38,7 @@ void testExpressionRest() { .contentType(ContentType.JSON) .accept(ContentType.JSON) .header("pepe", "pepa") - .body("{\"workflowdata\":{\"numbers\":[{\"x\":2, \"y\": 1},{\"x\":4, \"y\": 3}]}}").when() + .body("{\"workflowdata\":{\"numbers\":[{\"x\":2, \"y\": 1},{\"x\":4, \"y\": 3}]}, \"randomAdditionalProperty\":\"Im ignored in runtimes but will be visible on data index\"}").when() .post("/expression") .then() .statusCode(201)