i’ve created a simple bpmn with with the camunda modeler including an external task providing two test variables - a list and a map. After building with maven and deployment, these are shown as type “object” with a value of type “java.util.ArrayList” and “java.util.TreeMap”. I now want to fetch this task and the variables as JSON.
By default i get these variables as base64 encoded Java-serialized object via the REST API like:
“MapTest”: {
“type”: “Object”,
“value”: “rO0ABXNyABFqYXZhLnV0aWwuVHJlZU1hcAzB9j4tJWrmAwABTAAKY29tcGFyYXRvcnQAFkxqYXZhL3V0aWwvQ29tcGFyYXRvcjt4cHB3BAAAAAJ0AAVUZXN0MXQAATF0AAVUZXN0MnQAATJ4”,
“valueInfo”: {
“objectTypeName”: “java.util.TreeMap”,
“serializationDataFormat”: “application/x-java-serialized-object”
}
}
Another question is: i also wanted to add a plain JSON variable to my task as a test. So that the real type of the variable in the process engine is “json”. How do i define a json type variable via the modeler? I failed using expressions or inline javascript.
I’m using:
camunda modeler version 4.4.0
camunda process engine version 7.14
Hello @lucia ,
You can serialize your Java objects explicitly as JSON by using the Spin library JSON | docs.camunda.org
or you can set the defaultSerializationFormat to application/json:
Default Serialization Format
The engine can be configured to persist all objects for which no explicit data format is specified as JSON. The process engine configuration offers a property defaultSerializationFormat. To configure default JSON serialization, set this property to application/json. Now, the invocation runtimeService.setVariable(processInstance.getId(), "customer", new Customer()) directly serializes the customer object as JSON without explicit declaration of the format.
thanks for your reply. I’ve set the defaultSerializationFormat like mentioned in my post.
runtimeService.setVariable(processInstance.getId(), “customer”, new Customer())
But I don’t want to use JAVA staying inside the process engine - I want to use the REST API. And the defaultSerializationFormat setting seem to have no effect on the responses of the API.
Nevertheless i may take a look at the Spin library. Although i expect that a REST API should expose data in a non technology-bound way by default.
I used the plain camunda servlet project template in eclipse/maven and only set the defaultSerializationFormat and changed the bpmn model.
I’ve attached the bpmn file, so therefore you may can reproduce the problem.process.bpmn (6.5 KB)
After starting an instance, i checked the variables with the rest call: http://localhost:8080/engine-rest/external-task/fetchAndLock
BODY:
{
“workerId”:“aWorkerId2”,
“maxTasks”:10,
“usePriority”:true,
“topics”:
[{“topicName”: “ETTestJava”,
“lockDuration”: 5000
}]
}
Hi @lucia: Please set the defaultSerializationFormt in your bpm-platform.xml in Tomcat. You’ll find this in /server/apache-tomcat…/conf/bpm-platform.xml.
After restarting the defaultSerializationFormat is set and fetchAndLock returns all variables:
thanks for your hint! It works now and the Variables are send i json. I don’t understand why the json is not just plain in the variable value, but quoted in a string…but thats ok for me.
At my reasearch i found this jira post https://jira.camunda.com/browse/CAM-4835
…agreeing with the last comment: Adding the location of the setting to the user-guide would had been nice =)
greeting, JLucia