How to persist Custom Java Object in Process engine?

How to persist Custom Java Object in Process engine via Rest API?

Here is an example:

The value field must contain an escaped String of the serialized variable value (XML or JSON depending on the serializationDataFormat field).

For JSON data, the type should be always “Object” or we can use “JSON” as type. Because, the JSON String was constructed using new ObjectMapper().writeValueAsString(customObject);

I was using Camunda Rest API v7.9, Is that mandatory to add camunda-spin dependencies or pre-packaged?

The type depends on what you want to achieve with the variable. If you want an Object variable that the process engine will transparently provide as an instance of a custom class, then go with Object. Use JSON for variables that you want to treat as Spin JSON values on Java side.

If you use the default Camunda distributions, Spin is properly pre-configured.

1 Like

Thanks @thorben. Any suggestions for this?

When I use type: "JSON" I get:

Error: Request failed with status code 400 - Cannot deliver message: Unsupported value type 'JSON' {
  type: 'InvalidRequestException',
  message: "Cannot deliver message: Unsupported value type 'JSON'"

Only Object is supported?

UPDATE: Turns out this is very easy, just set e.g.

{"value": "{\"some\": \"JSON\"}", "type": "Json"}

Json is the magic undocumented type (as of 7.14).