Serialization / Deserialization
Turning app values into a sendable format such as JSON, then parsing that format back into values on the other side.
See it
What it is
Serialization turns in-memory data into bytes or text that can be stored or sent; deserialization reconstructs usable application values from that representation. JSON.stringify and JSON.parse are the common web pair. Protocol Buffers is a binary alternative when both sides share a schema and compact messages matter.
Use an explicit wire format at every service boundary. Decide how dates, money, enums, missing values, and identifiers are represented, then validate the decoded result before business code touches it. TypeScript types disappear at runtime, so parsing JSON does not prove that the incoming object matches an interface.
Round trips are not lossless by default. JSON turns Date values into strings, cannot serialize BigInt without custom handling, and omits undefined object properties. The larger danger is trusting decoded input: reject oversized or invalid payloads, and never use an unsafe deserializer that can construct executable objects from untrusted data.
Ask AI for it
Create a JSON boundary for this endpoint using JSON.stringify on output and a strict Zod schema with safeParse on input. Serialize Date values as ISO 8601 strings, money as integer minor units, and BigInt IDs as decimal strings; deserialize each one explicitly after validation. Reject unknown fields, malformed JSON, and bodies over 1 MB with an RFC 9457 error response, and add round-trip tests covering dates, missing optional fields, Unicode, and the largest valid ID.