ClassCastException when deserializing json process variable

I have tomcat with shared process engine, a application UI war an a seperate process war which contains bmpn and java delegates.
UI adds a json process variable when a user task is completed:

ObjectValue serializedProtocol = Variables.objectValue(receiveProtocol).serializationDataFormat("application/json").create();
variables.put("receiveProtocol", serializedProtocol);
taskService.complete(task.getId(), variables);

Next step is a service task, here we get a ClassCastException: xxx.ReceiveProtocol cannot be cast to xxx.ReceiveProtocol
when calling

ReceiveProtocol rp = (ReceiveProtocol) exe.getVariable("receiveProtocol");

When I replace this with:

ObjectValue ov = exe.getVariableTyped("receiveProtocol");
ReceiveProtocol rp = JSON(ov.getValueSerialized()).mapTo(ReceiveProtocol.class);

it works fine. It also works if I set asynchronous before on the service task.

Perhaps the variable is not deserialized and taken from some cache instead. This would be overoptimized because the classloader which initially created the variable is different from the delegates classloader.

Hi @bernd.frey,

I would assume exe.getVariable("receiveProtocol"); is returning String, that’s why you have to manually parse JSON after retrieval.


Hi @aakhmerov,

it is not returning String, this would cause ClassCastException: String cannot be cast to xxx.ReceiveProtocol. In my case it is returning ReceiveProtocol, but obviously by a different classloader.


right, so you put ObjectValue into variables, which never gets serialized as there is no wait state in the process. You could put in variables getValueSerialized(), but then you will have to manually deserialize.

ok, I understand. Would be nice if the variable would be serialized when the context switch occurs, not only in wait states.

Thanks for your help!