Serialization
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 replication. This includes:
-
Event sourced events and snapshots.
-
CRDT map keys and set elements, and LWWRegister values.
Cloudstate supports a number of types and serialization options for these values.
Primitive types
Cloudstate supports serializing the following primitive types:
Protobuf type | Java type |
---|---|
string |
java.lang.String |
bytes |
com.google.protobuf.ByteString |
int32 |
java.lang.Integer |
int64 |
java.lang.Long |
float |
java.lang.Float |
double |
java.lang.Double |
bool |
java.lang.Boolean |
The details of how these are serialized can be found here.
JSON
Cloudstate uses Jackson to serialize JSON. Any classes that are annotated with @Jsonable
will be serialized to and from JSON using Jackson.
The serialization of JSON values is described in Language support / Cloudstate serialization convention.
Note that if you are using JSON values in CRDT sets or maps, the serialization of these values must be stable. This means you must not use maps or sets in your value, and you should define an explicit ordering for the fields in your objects, using the @JsonPropertyOrder
annotation. This constraint is explained in CRDTs.