Incorrect representation of string process variable

When defining a single string value as a variable, e.g. str , zeebe incorrectly returns this variable with quotes around the actual value, e.g. "str" . I believe this is due to the representation of variables as JSON. When exporting such a variable record, the quotes are exported as well possibly breaking an application reading that exported record.

The use case I’m trying to implement when came across this is when trying to migrate a running process from an older version to a newer one.
As there in no straight forward way of migrating running processes from a version to another in camunda 8 what I’m trying looks like:

  1. Retrieve all variables from the running process using operate rest api
  2. Create and start a new process using the latest version as described here
  3. Adding variables retrieved at point 1 to the new process

Also here’s a code snippet of what I’m trying

        .variables(processInstanceDTO.getVariables()) //variables retrieved from operate api

Hi @bulivlad :wave:

Let me first check that I understand it correctly. The code snippet you shared results in new process instances where the variables are all JSON representations of the original variables. Right?

I’m not sure why Operate’s variables are represented like that, but it might be related to how you read the variables’ data. If it’s just a string containing the JSON representation, then you need to deserialize it into a Map<String,Object>, for example in Java you’d do that with using Jackson or Gson.

If you don’t always want to do that when creating your processInstanceDTO, then you could also do it at the moment where you call .variables(processInstanceDTO.getVariables()). It might be interesting for you to have a look at zeebe’s protocol-jackson module which can help with the deserialization of zeebe records.

hey @korthout,

Sorry, let me explain it a little bit better.
So I’m using the operate rest api to retrieve the process variables, which returns a list of variables in the format described here

 "key":                 <number>
 "processInstanceKey":  <number>
 "scopeKey":            <number>
 "name":                <string>
 "value":               <string> - Always truncated if value is too big in "search" results. In "get object" result it is not truncated.
 "truncated":           <boolean> - If true 'value' is truncated.

from there, I’m iterating the list of variables and transform them into a map with entries as [name: value] then starting the process using that map.

The result is that all variables are created like string - including numbers or jsons
Note the double quotes in the json structure, also the candidateId should be a number but is set as a string

Hmm, I see. Let me reach out to the Operate team, perhaps they can shed some light on this or how to deal with it.

Hello @bulivlad ,

Operate will always return variable values as string, this is why unchanged variable values will result in strings.

My suggestions would be to use a JSON parser like jackson to create the node structure of each variable value using objectMapper.readTree(variableValue) which will result in JsonNode instances.

The object mapper in the zeebe client should recognize them and serialize them as native json structure.

I hope this helps


1 Like