Hi all,
As a heads up: I am new to both Camunda and Java
My issue: I can serialize/deserialize a Java object in a delegate using execution.setVariable('varName', javaInstanceVariable);
. The workflow has only service tasks (all delegate code) and a gateway and successfully serializes/deserializes the object in each step. However, if I add a User Task in between any of the service tasks, then the object is no longer deserialized correctly…all of the properties are null and the parameterless constructor is called. With only service tasks, the parameterless constructor is not called.
My setup: I’m using the prebuilt distribution of Camunda 7.7 with Tomcat 8.0.24 and can see the Java object’s values by simply logging them in each service task.
Details:
My class:
public class Project {
private final Logger LOGGER = Logger.getLogger(Project.class.getName());
public static enum Types {
TYPE_1, TYPE_2, TYPE_3
private String _value;
private Types(final String val) {
_value = val;
}
public String toString() {
return _value;
}
}
private String id;
private Types type;
private String assignee;
public Project() {}
public Project(final String projectId, final Types projectType) {
id = projectId;
type = projectType;
}
// setters and getters
}
In the first service task, I instantiate this class using data from the submitted form, and set it to a variable:
Project instance = new Project(execution.getVariable('id').toString(), Types.valueOf(execution.getVariable('type').toString());
execution.setVariable('instance', instance);
…and retrieve the value by using:
Project instance = (Project) execution.getVariable('instance');
So, that will correctly set the properties id
and type
that were provided by the form in all service tasks before the User Task and the parameterless constructor is not called. After the the User Task completes, the instance
properties are null…and the parameterless constructor called.
I’m sure there’s something I’m not understanding about either execution context, variable hierarchy, or Java serialization. If there’s any more information that could be of use, please let me know.
Any help is much appreciated! Thanks!