Serialization converts in-memory objects into bytes for transport or storage, then deserialization reconstructs objects. It becomes necessary when Akka actors communicate across JVMs, whether on one host or different machines; persistent events likewise must be serialized before they reach a journal. section 8.5.1 section 9.3.5
For clustered actor protocols, bind a marker trait to a serializer and mix that trait into every message that crosses node boundaries. Jackson support offers JSON and CBOR choices: CBOR is binary, more compact, and described as having slightly better throughput, while JSON is text-based. section 8.4.3 section 8.5.1
serialization-bindings {
"example.countwords.CborSerializable" = jackson-cbor #1
}
A serialization binding maps the CborSerializable marker trait to the Jackson CBOR serializer, so marked protocol messages use that format. section 8.5.1
Choose serialization with the boundary and lifetime of data in mind:
- Use Jackson serialization for a straightforward Akka setup; Protocol Buffers offers better throughput and flexible schema development but takes more setup and maintenance. section 8.5.1
- Plan for schema evolution when persisting events. Older journal entries must still deserialize after fields are added, removed, split, or merged; preserve immutable historical facts rather than rewriting the past. section 9.3.5
- Use marshalling at an HTTP or RPC boundary. In Akka HTTP, a Marshaller[A,B] found through implicit resolution can convert values to JSON, while formatters describe custom case classes. section 11.1.5
Cargo HTTP endpoint
A cargo service accepts entityId, kind, and size request parameters, creates a Cargo value, and sends it to a sharded container. For reads, JSON formatters for Cargo and Cargos let an asynchronous actor response complete as a JSON payload. The same formatters can support request unmarshalling when the request entity contains the needed fields. section 11.1.6 section 11.1.5























