Cloudstate functions serve gRPC interfaces, and naturally the input and output messages are protobuf messages that get serialized to the protobuf wire format. However, in addition to these messages, there are a number of places where Cloudstate needs to serialize other objects, for persistence and for replication. This includes:

Cloudstate supports a number of types and serialization options for these values.

Serialization options

When creating EventSourced Entities, we can configure serialization for primitives or Json, using serializeAllowPrimitives or serializeFallbacktoJson, respectively. For example,

const EventSourced = require("cloudstate").EventSourced;

const entity = new EventSourced(
  ["shoppingcart.proto", "domain.proto"],
    persistenceId: "shopping-cart",
    snapshotEvery: 5, // Usually you wouldn't snapshot this frequently, but this helps to demonstrate snapshotting
    includeDirs: ["./"],
    serializeFallbackToJson: true // Enables JSON support for persistence