JGeek: POJO objects as job variables
As a mechanism to pass on output of one zeebe worker to another in a workflow, I am adding the pojo object instance to job variables when completing the command.
client.newCompleteCommand(job).variables(Map.of("employee",jsonUtils.mapper().convertValue(emp, MyEmployeeDTO.class))).send().join();
When I try to fetch them in the second zeebe worker code, I get a ClassCastException: class java.util.LinkedHashMap cannot be cast to class java.lang.String
MyEmployeeDTO myEmpDTO = mapper.readValue((String) job.getVariablesAsMap().get("emp"), MyEmployeeDTO.class);
looks like the json is converted to a map. Can someone guide me on how to fetch the pojo object back?
Thanks.
Josh Wulf: A variable in Zeebe terms is a string or number primitive. You can put a complex object into a variable by stringifying it, ie: serialising it as a string.
In the Node client, I use JSON.stringify to convert anything passed to the job.complete function, and in the worker task handler, I JSON.parse the incoming variables to turn any stringified JSON back into a JavaScript object.
I don’t know if this helps you at all - it may change your assumptions about how to serialise your object into Zeebe.
JGeek: It indeed helps. I converted the json to a string and read it accordingly thanks !
Note: This post was generated by Slack Archivist from a conversation in the Camunda Platform 8 Slack, a source of valuable discussions on Camunda 8 (get an invite). Someone in the Slack thought this was worth sharing!
If this post answered a question for you, hit the Like button - we use that to assess which posts to put into docs.