Cannot find serializer for value 'ObjectValue

There are couple of threads that I can see on this serializer problem and no conclusion force me to ask the below question . Hope I will get some help to clear my doubts.
I am using JDK 1.8 Camunda 7.11.X

I have a simple POJO which is getting populated by a rest service and I am setting the pojo in the camunda to kick start a process

camunda.getRuntimeService().startProcessInstanceByKey(//
        ProcessConstants.PROCESS_KEY_WORkFLOW,orderRequest.getOrderId(), //
        Variables //
          .putValue(ProcessConstants.VAR_NAME_ORDER_REQUEST, orderRequest) //
          );

I can see it is giving error about no serializer which is quite fare. When I see the camuda document I use the below syntax to provide a serializer but then also it is giving the exception as “Cannot find serializer for value 'ObjectValue”

ObjectValue customerDataValue = Variables.objectValue(customerData)
  .serializationDataFormat(Variables.SerializationDataFormats.JAVA)
  .create();

execution.setVariable("someVariable", customerDataValue);

Also when I marked the pojo as transient as well then also It is giving the same error .

Only it is getting solved after I implement “Serializable” interface in the POJO. Can anyone help me in understanding the behavior?

1 Like

Hello @anisk,

Based on the following

"When an object value is passed to the process engine, a serialization format can be specified to tell the process engine to store the value in a specific format. Based on this format, the engine looks up a serializer . The serializer is able to serialize a Java object to the specified format and deserialize it from a representation in that format. That means, there may be different serializers for different formats and it is possible to implement custom serializers in order to store custom objects in a specific format.

The process engine ships one built-in object serializer for the format application/x-java-serialized-object . It is able to serialize Java objects that implement the interface java.io.Serializable and applies standard Java object serialization. "

Therefore you are seeing the expected behavior of the engine. In other words the engine needs to know that your Java object is serializable to know how to set and get the object from the engine.

More on this topic can be found here.

Please let me know if you have any questions.

Regards,

2 Likes

If we mark the object as transient , then also do we need to implement java.io.Serializable interface ? I guess for transient it would behave like as primitive data type as it is not required to store in the database , it is something to keep in JVM memory only ?

Hey @anisk,

Camunda will always serialize your custom object type and by default it will serialize to XML or JSON (whichever serializer is first on your classpath) when you set a variable as a process variable. If you wish to serialize to/from Java then you still need to make sure to mark your Java class as serializable. Additionally, transient custom object types will be serialized to and from the JVM as well even if not stored in the db.

So to answer your question. Yes, you should implement serializable if you want to serialize your object to Java to/from the JVM and serialize the process variable. Otherwise your object will be serialized to XML or JSON by default.

What is the reason to serialize to Java and not use the standard behavior? We recommend serializing to JSON as it makes it easy to read to other applications accessing your db or object.

Here is an image that shows the standard serialization which Camunda uses as well.

I also just tried this in my local environment.

Regards,

1 Like