Skip to content

Commit b912b04

Browse files
Change json deep copy to in/out parameter handling
1 parent d856bab commit b912b04

6 files changed

Lines changed: 100 additions & 4 deletions

File tree

modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/util/IOParameterUtil.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.slf4j.Logger;
2525
import org.slf4j.LoggerFactory;
2626

27+
import com.fasterxml.jackson.databind.JsonNode;
28+
2729
/**
2830
* @author Filip Hrisafov
2931
*/
@@ -61,6 +63,10 @@ protected static void processParameters(List<IOParameter> parameters, VariableCo
6163
} else {
6264
value = sourceContainer.getVariable(parameter.getSource());
6365
}
66+
67+
if (value != null && value instanceof JsonNode) {
68+
value = ((JsonNode) value).deepCopy();
69+
}
6470

6571
String variableName = null;
6672
if (StringUtils.isNotEmpty(parameter.getTargetExpression())) {

modules/flowable-engine/src/main/java/org/flowable/engine/impl/util/IOParameterUtil.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import org.slf4j.Logger;
2727
import org.slf4j.LoggerFactory;
2828

29+
import com.fasterxml.jackson.databind.JsonNode;
30+
2931
/**
3032
* @author Filip Hrisafov
3133
*/
@@ -74,6 +76,10 @@ protected static void processParameters(List<IOParameter> parameters, VariableCo
7476
} else {
7577
value = sourceContainer.getVariable(parameter.getSource());
7678
}
79+
80+
if (value != null && value instanceof JsonNode) {
81+
value = ((JsonNode) value).deepCopy();
82+
}
7783

7884
String variableName = null;
7985
if (StringUtils.isNotEmpty(parameter.getTargetExpression())) {

modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/multiinstance/MultiInstanceNoWaitStatesTest.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,14 @@
3030
import org.flowable.engine.runtime.ProcessInstance;
3131
import org.flowable.engine.test.Deployment;
3232
import org.flowable.job.api.Job;
33+
import org.flowable.task.api.Task;
3334
import org.flowable.variable.api.persistence.entity.VariableInstance;
3435
import org.junit.jupiter.api.Test;
3536

37+
import com.fasterxml.jackson.databind.JsonNode;
38+
import com.fasterxml.jackson.databind.node.ArrayNode;
39+
import com.fasterxml.jackson.databind.node.ObjectNode;
40+
3641
/**
3742
* @author Filip Hrisafov
3843
* @author Joram Barrez
@@ -144,8 +149,6 @@ public void testParallelAsyncAndExclusiveSubProcess() {
144149
assertNoJobsAndNoProcessInstances();
145150
}
146151

147-
148-
149152
@Test
150153
@Deployment
151154
public void testNestedParallelAsyncAndExclusiveSubProcess() {
@@ -181,6 +184,30 @@ public void testNestedParallelAsyncAndExclusiveCallActivity() {
181184
waitForJobExecutorToProcessAllJobs(Duration.ofMinutes(5).toMillis(), 200);
182185
assertNoJobsAndNoProcessInstances();
183186
}
187+
188+
@Test
189+
@Deployment
190+
public void testJsonArrayVariable() {
191+
ArrayNode customerArray = processEngineConfiguration.getObjectMapper().createArrayNode();
192+
ObjectNode customer1Node = customerArray.addObject();
193+
customer1Node.put("name", "John Doe");
194+
ObjectNode customer2Node = customerArray.addObject();
195+
customer2Node.put("name", "Jane Doe");
196+
197+
ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder()
198+
.processDefinitionKey("jsonVarTest")
199+
.variable("customerList", customerArray)
200+
.start();
201+
202+
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
203+
taskService.complete(task.getId());
204+
205+
ArrayNode persistedCustomerArray = (ArrayNode) runtimeService.getVariable(processInstance.getId(), "customerList");
206+
JsonNode persistedCustomer1Object = persistedCustomerArray.get(0);
207+
208+
assertThat(persistedCustomer1Object.has("newProperty")).isTrue();
209+
assertThat(persistedCustomer1Object.get("newProperty").asText()).isEqualTo("test");
210+
}
184211

185212
protected void assertNoJobsAndNoProcessInstances() {
186213
assertThat(managementService.createJobQuery().count()).isEqualTo(0);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* Licensed under the Apache License, Version 2.0 (the "License");
2+
* you may not use this file except in compliance with the License.
3+
* You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*/
13+
package org.flowable.engine.test.bpmn.multiinstance;
14+
15+
import org.flowable.engine.delegate.DelegateExecution;
16+
import org.flowable.engine.delegate.JavaDelegate;
17+
18+
import com.fasterxml.jackson.databind.node.ObjectNode;
19+
20+
public class TestJsonDelegate implements JavaDelegate {
21+
22+
@Override
23+
public void execute(DelegateExecution execution) {
24+
ObjectNode customerNode = (ObjectNode) execution.getVariable("customer");
25+
customerNode.put("newProperty", "test");
26+
}
27+
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<definitions id="definition"
3+
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:flowable="http://flowable.org/bpmn"
6+
targetNamespace="Examples">
7+
8+
<process id="jsonVarTest">
9+
10+
<startEvent id="theStart" />
11+
<sequenceFlow id="flow1" sourceRef="theStart" targetRef="task1" />
12+
13+
<userTask id="task1" />
14+
15+
<sequenceFlow id="flow2" sourceRef="task1" targetRef="serviceTask1" />
16+
17+
<serviceTask id="serviceTask1" flowable:class="org.flowable.engine.test.bpmn.multiinstance.TestJsonDelegate">
18+
<multiInstanceLoopCharacteristics isSequential="true" flowable:collection="${customerList}" flowable:elementVariable="customer" />
19+
</serviceTask>
20+
21+
<sequenceFlow id="flow3" sourceRef="serviceTask1" targetRef="task2" />
22+
23+
<userTask id="task2" />
24+
25+
<sequenceFlow id="flow4" sourceRef="task2" targetRef="theEnd" />
26+
27+
<endEvent id="theEnd" />
28+
29+
</process>
30+
31+
</definitions>

modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/types/JsonType.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ public void setValue(Object value, ValueFields valueFields) {
117117
} else {
118118
JsonNode jsonNode = (JsonNode) value;
119119

120-
jsonNode = jsonNode.deepCopy();
121-
122120
String textValue = value.toString();
123121
if (textValue.length() <= maxLength) {
124122
valueFields.setTextValue(textValue);

0 commit comments

Comments
 (0)