liveBook · Manning

Serialization

As explained in API Design Patterns

A serialization protocol is a defined mechanism for converting structured data into a transferable representation and reconstructing it later.

Serialization converts structured in-memory data into language-agnostic bytes for transfer, while deserialization reconstructs client-side data. Because languages differ, every protocol loses some information. section 5.0 section 5.1

Figure 5.1 Data moving from API server to client

Follow the data path from an API server’s structured resources to serialized bytes and back into a client representation. section 5.1

Design serialization around the format exposed by the API, not merely the types of its implementation language:

  • Choose representations that work across client languages, commonly using JSON and its available data types. section 5.1
  • Treat null, omitted fields, and empty values as distinct cases when defaults and input behavior matter. section 5.0
  • Avoid assuming numeric values survive unchanged across languages, especially beyond 32-bit or 64-bit limits and with decimal precision. section 5.3.3

Preserving decimal values

Serialize decimal values such as 0.1 and 0.2 as strings, then parse them with Decimal.js before arithmetic. This avoids JSON number parsing and floating-point precision problems. section 5.3.3

Resource transfer and bulk export need not share one format. JSON may suit individual resources, while newline-delimited JSON, CSV, or TSV can suit exports; compression, encryption, and file splitting can follow serialization. Keep data retrieval separate from format processing so sources and destinations remain reusable. section 23.3.3

How API Design Patterns covers it

How deep it goes
Explains transfer, lossiness, numeric hazards, export formats, and post-processing, but does not detail protocol internals.
Examples
Uses API resources, JSON numeric comparisons, Decimal.js arithmetic, CSV messages, and JSON, CSV, ZIP, or BZ2 configurations.
What it assumes
Assumes basic API and programming-language data-type knowledge while establishing cross-language representation and default-value concerns.
What you can do after
Apply it via JSON or export formats while accounting for precision, defaults, compression, encryption, and client compatibility.
How it connects
Connects data types, JSON, deserialization, programming languages, API export, compression, encryption, and filtering.

Also explained in

Compare how 24 books explain serialization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of API Design Patterns. The section links point to the parts of the book it draws on.