Can Platform use JSON as default instead of HashMap?

Hi,

I am using Camunda Platform Run only with External Task Pattern (no Java, no Maven).

I use a client that does not provide the datatype of variables and relies on defaults from Camunda platform. Which works great so far. Though, when I send a variable that represents a Map, it gets automatically converted inside Camunda platform in to a java.util.LinkedHashMap.

Can I configure Camunda platform in such a way, that maps always are stored as JSON instead of a LinkedHashMap?

Regards,
Markus

you need to serialize the java.util.LinkedHashMap as JSON string and set type as ‘Json’.

I know I can rewrite the client. But since java.util.LinkedHashMap does not make sense in Camunda Platform without Java Delegates, I thought there maybe is an option to configure JSON as default on serverside.

1 Like

Hi @Noordsestern,

I had a look into this and didn’t found a single link in the docs about this topic.

So here are some findings from reading code:

You can add a JSON process variable if you have Camunda SPIN installed (which is default in Camunda RUN).

The request for starting a process instance with a JSON variable looks like this:

curl --location --request POST 'http://localhost:8080/engine-rest/process-definition/key/complexDataProcess/start' \
--header 'Content-Type: application/json' \
--data-raw '{
    "variables": {
        "jsonVar": {
            "value": "{\"name\" : \"jonny\", \"address\" : {\"street\" : \"12 High Street\", \"post code\" : 1234}}",
            "type": "Json"
}
},
"withVariablesInReturn": true
}'

The engine saves the variable as an Object of type Json. The ACT_RU_VARIABLE table references a byteArray with the value.

You will get the variable in a fetch and lock as a Json object as well:

   "jsonVar": {
       "type": "Json",
       "value": "{\"name\" : \"jonny\", \"address\" : {\"street\" : \"12 High Street\", \"post code\" : 1234}}",
       "valueInfo": {}
   }

Now it depends on your worker logic, how to access the variable in your code. After changing the value, it must be submitted as type Json again.

The types Json and XML are added in the camunda-engine-plugin-spin.

Please let me know how this type is handled in Python.

Hope this helps, Ingo

1 Like

Thank you @aravindhrs and @Ingo_Richtsmeier

Yes, that’s what I did in the end. I implemented in my python client that Map structures are always serialized as JSON.

Unfortunately, the fix breaks DMN expression where people had used javascript in order to evaluate JavaMaps. But well.