try {
ObjectInputStream objectStream;
if (token != null) {
ProcessDefinition processDefinition = token.getProcessInstance().getProcessDefinition();
ClassLoader classLoader = JbpmConfiguration.getProcessClassLoader(processDefinition);
objectStream = new CustomLoaderObjectInputStream(memoryStream, classLoader);
}
else {
objectStream = new ObjectInputStream(memoryStream);
}
return (Serializable) objectStream.readObject();