Skuld.Comp.SerializableStruct (skuld v0.1.15)

View Source

Utilities for converting structs to/from JSON-friendly maps.

Encoded structs include a __struct__ field so they can be faithfully reconstructed after decoding (e.g., from Jason.decode/1). Keys are expected to already exist as atoms in the system to avoid dynamic atom creation.

Summary

Functions

Reconstructs a struct from a decoded JSON map produced by encode/1. If the map doesn't include struct metadata, it is returned unchanged.

Convert a struct into a map representation suitable for JSON encoding.

Functions

decode(map)

@spec decode(map()) :: struct() | map()

Reconstructs a struct from a decoded JSON map produced by encode/1. If the map doesn't include struct metadata, it is returned unchanged.

encode(value)

@spec encode(struct()) :: map()

Convert a struct into a map representation suitable for JSON encoding.