I created a BPMN Collaboration model with a Script-Task of type Javascript in it. Then I instantiated a process instance with a process variable like so:
Variable name: arr
Object type name: java.util.ArrayList
Serialization Data Format: application/x-java-serialized-object
Value: [{ "id": 10 }]
Then I passed the script task with the following code:
var arr = execution.getVariable("arr");
execution.setVariable("arr2", arr);
And it ran successfully. Then I amended the script task like this:
var arr = execution.getVariable("arr");
arr.add({ "id" : 2 });
execution.setVariable("arr2", arr);
And redeployed, re-instantiated; and to my surprise it resulted in an error:
Cannot submit task form xxx: Cannot serialize object in variable 'arr': jdk.nashorn.internal.scripts.JO4
Can someone please tell me what am I doing wrong?
[UPDATE]
I just found something new, if I modify the ArrayList like this:
var arr = execution.getVariable("arr");
arr.add(2);
execution.setVariable("arr2", arr);
It works just fine! And the modified value is:
[{ "id": 10 }, 2]
Which means setVariable
has problem serializing the modified list. So how should I serialize it?