Patterns for POJO serialization/deserialization

Hello,

Could someone share the patterns you are using to serialize and deserialize POJO when setting variables for the process?

I see by default Zeebe Java client serialize the objects as maps.

Hey!
You could easily rely on Jackson in order to use something like this:

import com.fasterxml.jackson.databind.ObjectMapper; 
import com.fasterxml.jackson.databind.ObjectWriter; 

ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
String json = ow.writeValueAsString(object);

Besides, the Camunda SPIN library could also be a good package to check out.

Hopefully this was helpful to you! :slight_smile:
Best,
Thomas

Hey Thanks.

I ended up doing something similar, just a bit more. Here is the code in Kotlin

inline fun <reified T> ActivatedJob.getVariableAsType(key: String): Result<T> {
        return try {
            val json =
                zeebeCustomMapper.toJson((this.variablesAsMap[key] as LinkedHashMap<*, *>))
            Result.success(zeebeCustomMapper.fromJson(json, T::class.java))
        } catch (ex: IOException) {
            Result.failure(ex)
        }
    }
2 Likes