Hi,
I need some advice about how to serialize object, pass it as variable and in task read as object of the same class.
Consider following setup:
- “SERVER” Camunda running as a spring boot application
- “TASKCLIENT” ExternalTaskClient java (org.camunda.bpm.client.ExternalTaskClient) subscribes on some topics
- “RESTCLIENT” Camunda REST client Spring-Boot
Here is my scenario:
On the RESTCLIENT i start a process and add a variable containing array of objects all extending some base abstract class.
On the SERVER this class needs to be resolved accordingly as well as on the TASKCLIENT
All three share one jar file defining the abstract class and the childs.
Q: How can I tell camunda to know this type when used? All I get in camunda is:
java.util.ArrayList for the collection
and for single item in the collection i get java.util.LinkedHashMap
Also is this apporach correct?
@zachomar refer this section:
Thanks,
I am able to propagate the class name to the Camunda now using following code on the RESTCLIENT side:
String serialized = new ObjectMapper().writeValueAsString(someObject);
ObjectValue dataValue = Variables.serializedObjectValue()
.objectTypeName(someObject.getClass().getName())
.serializationDataFormat(Variables.SerializationDataFormats.JSON)
.serializedValue(serialized).create();
VariableMap variables = Variables.createVariables();
variables.put("someName", dataValue);
ProcessInstance instance = service.startProcessInstanceByKey("procesKey", UUID.randomUUID().toString(), variables);
However when I try to retrieve the value by
SomeClass item = (SomeClass) service.getVariable(instance.getId(), "someName");
results in exception:
class java.util.LinkedHashMap cannot be cast to class com.sample.common.SomeClass
(java.util.LinkedHashMap is in module java.base of loader 'bootstrap'; com.sample.common.SomeClass is in unnamed module of loader 'app')