String list variable is null after using VariableValueDto.toMap

Hi there,

I am building a custom web api similar to the built-in rest api.
I tried to convert the passed-in variables to VariableMap using VariableValueDto.toMap() in order to pass it to the setVariables function.
I used this data in the rest request:
“variables”: {
“otHours” : {
“value” : 8,
“type”: “Integer”
},
“list”: {
“value”: “["1","2"]”,
“type”: “Object”,
“valueInfo” : {“objectTypeName”: “java.util.ArrayList”, “serializationDataFormat”:“application/json”}
}
}

The simple variable otHours was correctly set in the VariableMap, but the list object was null.

Any help will be much appreciated!

Hi Leoric, welcome to the community!
How do you initialize the startProcessRequest and objectMapper object?
What if you debug the variables oject, do you find your list inside?
Thanks

Hi @Leoric ,

in addition to what Enrico already said, I am curious why you would need to convert the variables into the VariableMap object yourself. Usually you would just send your “casual java map with java types” to one of camundas services (e. g. RuntimeService incase of process instantiation) and let them handle everything else. This would prevent possible mistakes in data conversion.

So I would expect your rest api to take any json object as variables like:

"variables": {
    "otHours" : 8,
    "list": ["1","2"],
}

Then the ObjectMapper will serialize the rest request into a java map with some list implementation for the list variable. Then you would send this map as variables to e. g. the runtime as service. Camunda would then convert the java map to the internal VariableMap object including type information etc. Obviously this approach only works if you are not required to specify special types within the rest request. Primitive data types, list, maps will work.

Kind regards
Adagatiya

Hi Enrico, Adagatiya,

Thanks for the help.
I will need to support Date data type. So I will stick to the VariableValueDto.

It seems that the list variable is successfully stored into the process instance even if it is null when I debugged it.
I guess it is serialized somewhere after it is passed to the process engine.

Thanks again for your help! I am good now as long as it works.