Converting result of external Task into JSON: where is the right place to do it?

What is the correct abstraction / place to converts data formats in a process?

Let me make an example: I have an external task which results in a complex Java object to be added as the process variables. In some processes, I need this data to be visible through user forms and therefore I need to convert to Json.

I don’t want to convert the object into json inside the code that performs the external task because this doesn’t apply to all processes (and therefore would lead to duplication). Should I add an en Execution Listener to perform this operation or should I add a send task?

Hi @Edmondo_Porcu,

You can tell the process engine to serialize your Java object as JSON. Then you can retrieve the deserialized Java object as well as the serialized JSON value via API. See the corresponding documentation here: https://docs.camunda.org/manual/latest/user-guide/data-formats/json/#serializing-process-variables

Cheers,
Thorben

1 Like

@thorben my apologies for reviving an old thread but JSON serialization appears to be broken with respect to external tasks. We’ve been working around the issue by serializing JSON as strings for a couple of months now but it’s an imperfect workaround and is increasingly becoming a problem.

The crux of the issue is that Camunda appears to store the Java class with the serialized value and both the engine and external task client attempt to use the original class to deserialize the value. Of course in the context of an external task running in a different JVM, the class is not in the classpath and this results in a class not found exception.

I don’t understand why Camunda stores the class value at all. It defeats the purpose of serialization. Please see Serialization issue with external tasks for further details.