Serialization of JSON variables

I am new to camunda, and using a spring boot generated project.
I’m trying to store a list in the context variables, and the easiest way I found was to use JSON arrays.
The problem I am having with JSON variables (before using arrays) is that the call of :

execution.setVariable(“myVariable”, myJSONObject);

in a java delegate doesn’t actually add this variable in the process instance variables.
(the variable myJSONObject being a “org.camunda.spin.plugin.variable.value.JsonValue”)

I found similar topics on the subject, but couldn’t find any solution to my problem.

I used to have an error like “Cannot serialize object in variable”, but it disappeared when I tried adding a default value of “application/json” for the property “defaultSerializationFormat” in my process.xml file. (is it really in this file that I was supposed to add this ?)
This only got rid of the error, and didn’t really solve the problem : now the process finishes, but without adding the variable.
I think it has something to do with the serialization of this object when I set it in the instance variables.

Does anyone have an idea please ?

I think this docu might help solving your problem: JSON |

So in the end your delegate should contain something like this:

JsonValue jsonValue = SpinValues.jsonValue(json).create();
    execution.setVariable("customerJonny", jsonValue);

Does this answer your question? :slight_smile:

1 Like

Hi @Hafflgav ,
Thanks you for your answer.
Actually what I was doing worked, but I thought I could see the variable when loading variables in the tasklist (which is apparently not the case).
Also I forgot to fetch the variable in my second embedded form…
Sorry for wasting your time, have a nice day