The basics of serialization
Serialization is the process of converting data into a format that allows you to transfer it, store it, and later deconstruct it.
Serialization has two primary use cases:
- Transferring data between services, acting as a common format between them
- Encoding and decoding arbitrary data for storage, allowing you to store complex data structures as byte arrays or regular strings
In Chapter 2 Scaffolding a Go Microservice, while scaffolding our applications, we created our HTTP API endpoints and set them to return JSON responses to the callers. In that case, JSON played the role of a serialization format, allowing us to transform our data structures into it and then decode them back.
Let’s take our Metadata
structure defined in the metadata/pkg/model/metadata.go
file as an example:
// Metadata defines the movie metadata.
type Metadata struct {
ID string 'json:"id"'
Title string...