Serializability

Infinitic is still in active development. Subscribe here to follow the progress.

Why must task and workflow parameters and return value be serializable/deserializable?

  • when a client dispatches a task / workflow, it serializes parameters before sending them (along with class name and method name)
  • when a task worker receives a task to execute, it deserializes those parameters
  • when a workflow worker uses a task output in a workflow, it deserializes it

Primitives (number, string, etc...) being natively serializable/deserializable, this requirement must be checked only for objects contained in tasks parameters or return value.

Checking Serializability In Java

For Java, Infinitic uses FasterXML/jackson to serialize/deserialize into/from JSON.

If o1 is a CarRentalCart object used in the parameters of a task (or as return value), we should be able to run this:

ObjectMapper objectMapper = new ObjectMapper();
String json = objectMapper.writeValueAsString(o1);
CarRentalCart o2 = objectMapper.readValue(json, o1.getClass());
assert o1.equals(o2);

(ObjectMapper being com.fasterxml.jackson.databind.ObjectMapper)

Checking Serializability In Kotlin

For Kotlin, we recommend using kotlinx-serialization-json in our models.

If o1 is a CarRentalCart object used in the parameters of a task (or as return value), we should be able to run this:

val json = Json.encodeToString(CarRentalCart.serializer(), o1)
val o2 = Json.decodeFromString(CarRentalCart.serializer(), json)
require(o1 == o2)

(Json being kotlinx.serialization.json.Json)

An easy way to reach this requirement is to use data classes with a kotlinx.serialization.Serializable annotation. For example :

@Serializable
data class CarRentalCart(
    val cartId: String
)

If kotlinx-serialization-json is not used, the fallback serialization/deserialization method will be FasterXML/jackson as for Java.

Edit this page on GitHub Updated at Fri, May 28, 2021