When using a serialized representation of variables, the Java serialization format is forbidden by default. You should either use another format (JSON or XML), or explicitly enable the Java serialization with the help of javaSerializationFormatEnabled configuration parameter.
@Getter
@Builder
@ToString
@AllArgsConstructor
public class Order implements Serializable {
private static final long serialVersionUID = 1L;
private final String orderId;
private final String orderType;
private final String orderName;
private final double orderPrice;
}
ObjectSerializeDelegate.java:
@Component
public class ObjectSerializeDelegate implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
Order order = Order.builder().orderId("OR3487").orderName("Laptop").orderPrice(80000.00).orderType("Electronics")
.build();
execution.setVariable("orderDataJava",
Variables.objectValue(order).serializationDataFormat(Variables.SerializationDataFormats.JAVA).create());
}
}
ObjectDeserializeDelegate.java:
@Slf4j
@Component
public class ObjectDeserializeDelegate implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
ObjectValue typedObjectOrderValue = execution.getVariableTyped("orderDataJava");
log.info("Type name:{}, SerializationDataFormat:{}", typedObjectOrderValue.getObjectTypeName(),
typedObjectOrderValue.getSerializationDataFormat());
Order deserializedOrder = (Order) typedObjectOrderValue.getValue();
log.info("deserializedOrder:{}", deserializedOrder);
}
}
Logs:
2020-08-13 00:32:13.553 INFO 5324 --- [aTaskExecutor-2] c.e.w.d.ObjectDeserializeDelegate : Type name:com.example.workflow.dto.Order, SerializationDataFormat:application/x-java-serialized-object
2020-08-13 00:32:13.554 INFO 5324 --- [aTaskExecutor-2] c.e.w.d.ObjectDeserializeDelegate : deserializedOrder:Order(orderId=OR3487, orderType=Electronics, orderName=Laptop, orderPrice=80000.0)
I had similar approach but then i am assuming the variable across other process too i figured out the issue , when type casted from A to B , both A and B should be also in the similar package to get the serialized value back into string
@Slf4j
@Component
public class ObjectDeserializeDelegate implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
ObjectValue typedObjectOrderValue = execution.getVariableTyped("orderDataJava");
log.info("Type name:{}, SerializationDataFormat:{}", typedObjectOrderValue.getObjectTypeName(),
typedObjectOrderValue.getSerializationDataFormat());
Order deserializedOrder = (Order) typedObjectOrderValue.getValue();
log.info("deserializedOrder:{}", deserializedOrder);
}
}
@Component
public class ObjectSerializeDelegate implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
Order order = Order.builder().orderId("OR3487").orderName("Laptop").orderPrice(80000.00).orderType("Electronics")
.build();
ObjectValue orderTypedObjectValue = Variables.objectValue(order)
.serializationDataFormat(Variables.SerializationDataFormats.JAVA).create();
execution.setVariable("orderDataJava", orderTypedObjectValue);
}
}
@Getter
@Builder
@ToString
@AllArgsConstructor
public class Order implements Serializable {
private static final long serialVersionUID = 1L;
private final String orderId;
private final String orderType;
private final String orderName;
private final double orderPrice;
}
thanks arvind , infact i had tried all this
variables.put(WorkerProperties.SOME_VALUE,
Variables.objectValue(headerObjectValues).
serializationDataFormat(Variables.SerializationDataFormats.JSON).
create());
Just for the record, this issue was resolved after Java beans were packaged in JAR, and placed in camunda-bpm-run-ee-7.13.1-ee/configuration/userlib.
The cause that for this issue was:
When call-activity tries to map the process variables, it tries to get Typed value of process variable. And at that point it fails to deserialize it as it can not find the class in the context of process engine (where process is deployed).