Use json for non-serializable results

Hi - the default java serialization for variables is fine and preferrable - but is there some way to make camunda use for instance spin’s json feature if an result variable does not implement Serializable?

I want to call my plain Spring POJOs from BPMN via expressions to avoid polluting it with camunda api’s - so I don’t have the camunda api’s directly available for calling the type stuff (to set application/json).

So I wonder if

  1. a default fallback for objects not implementing Serializable is possible, alternatively
  2. if a object->json transformation can be defined to be called in the modelleling UI?
1 Like

Hi @davidkarlsen,

if the classes didn’t implement the Serializable interface, the engine will serialize the objects as json or xml automatically. The format depends on the first serializer which is found on the classpath. I’ve tried it by myself, the objects were serialized in XML.

Setting the defaultSerializationFormat to application/json in the process engine configuration (for wildfly in standalone.xml, otherwise bpm-platform.xml) the objects are stored as JSON. See the last box at: https://docs.camunda.org/manual/7.10/user-guide/data-formats/json/#serializing-process-variables

Hope this helps, Ingo

2 Likes

Hm, I use the spring-boot default config (which sets java serialization as default) - but it seems to not be able to fall back to using json. I guess if I set application/json it will use it for all objects - including Serializable ones

1 Like

Hi @davidkarlsen,

I just tested it by myself for satisfying my curiosity.

My findings from running the example in Spring boot with an application created from our spring boot archetype: https://docs.camunda.org/manual/7.10/user-guide/process-applications/maven-archetypes/#overview-of-available-maven-archetypes (spring-boot is available, but not mentioned here)

Classes implement Serializable: Data saved as bytes. As you mentioned it as default setting.

Classes didn’t implement Serializable: Data saved as application/json, maybe because Jackon is found as the first serializer (See my post before).

Configure default-serialization-format in application.yaml and classes implement Serializable: Data saved as application/json.

Cheers, Ingo

2 Likes

Hm, I still get:

org.camunda.bpm.engine.ProcessEngineException: Cannot find serializer for value 'Untyped value 'class V1Namespace {

my application.yaml:

camunda:
bpm:
admin-user:
id: kermit
password: superSecret
firstName: Kermit
filter:
create: All tasks
default-serialization-format: application/json

1 Like

Hi,

I also get issues with the serialization format.
I had posted about it here How to iterate over SpinList with javascript
How can I check which serializer is selected first, as @Ingo_Richtsmeier mentions above?
Where do I set the “defaultSerializationFormat = application/json” as mentioned in the docs https://docs.camunda.org/manual/7.10/user-guide/data-formats/json/#serializing-process-variables?
Where exactly in the standalone.xml file?

Thx

1 Like

Hi,

I have a hashmap

Map<Long, String> tasks = new HashMap<Long, String>();

When I save it to a process variable:

execution.setVariable(“tasks”, tasks);

it is serialized as application/json

image

That’s because I have set the engine’s “ defaultSerializationFormat = application/json

So far, so good.

At some point I retrieve this process variable and when I try to get the Long key of the hashmap I get an error

java.lang.String cannot be cast to java.lang.Long

Apparently it considers the key as Strings.

How to solve this?
I tried also to save my process variable as:

ObjectValue tasksDataValue = Variables.objectValue(tasks)
        .serializationDataFormat(Variables.SerializationDataFormats.JAVA)
        .create();
execution.setVariable("tasks",tasksDataValue);

OR

    ObjectValue tasksDataValue = Variables.objectValue(tasks)
            .serializationDataFormat("application/x-java-serialized-object")
            .create();
    execution.setVariable("tasks",tasksDataValue);

but still get the same error (variable is still serialized as application/json).

Any idea?

Thanks

Any solutions here?

Not working for me.

  1. I have set in application.yml default-serialization-format: “application/json”. My class does not implement Serializable interface. I got an error: “Cannot find serializer for value ‘ObjectValue’…”

  2. Serialization as bytes: class implements serializable, default-serialization-format not set in application.yml but this is not what I want.

After adding Camunda Spin plugin everything works like charm!