The processVariables is a Hashmap defined as below: Map<String, Object> processVariables= new HashMap<String, Object>();
Within the HashMap we have added a List of objects like below, where the list contains 3 instances of object type OrderRequest
List<OrderRequest> orderRequests= new ArrayList<OrderRequest>();
processVariables.put("orderRequests", orderRequests);
The worker is completed successfully and the variable is depicted correctly in simple monitor app.
After this we try within a subsequent service task to read one entry from the list using
but the last expression fails with java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class OrderRequest.
Is there any other way where we can write a list of objects as a process variable and read the elements of the list as objects correctly in a subsequent service task?
Are only list of primitives retrieved correctly from workers?
OrderRequest class contains three String variables and getters/setters
public class OrderRequest {
private String orderRequestId;
private String orderRequestNumber;
private String orderRequestStatus;
}
Thanks for the feedback!
I made a test and the proposed solution works.
An additional question. The job.getVariablesAsType method does not provide an input argument for specifying the variable that needs to be retrieved.
In case we have multiple variables with different object types/or simple primitives, how does this work internally, does it simply ignore all other variables?
If we have two different process variables variable1 and variable2 with the same object type, which one of the variables will it fetch, one randomly. Through testing I think it fetches the first one in ascending alphabetical order?
In such a case how can we overcome the issue? Would we need to save the variable as String ,retrieve the variable as string and use custom Jackson code to desereliaze it afterwards to Java object?
Technically could the zeebe client API be modified, so that we could specify which variable to fetch and provide some meta information (such as the object type, or even a List<ObjectType.class>) so that variables could be deserialized correctly as objects?