How to persist Custom Java Object in Process engine?

Here is an example: https://docs.camunda.org/manual/7.9/reference/rest/process-instance/variables/put-variable/#request-1

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