DDD.Serializer (vicander v0.1.1)

Copy Markdown View Source

Converts nested entities to JSON-ready maps and back.

Used by DDD.Type to store {:list, Entity}, {:one, ValueObject} and the other nested field types in a jsonb column. load/2 fills defaults for keys missing from old rows and seals the rebuilt struct (the data is trusted, it came from the store).

Summary

Functions

Dump a struct to a map with string keys.

Dump a value of the given field type to a JSON-ready term.

Rebuild a sealed struct of module from a dumped map (string or atom keys).

Load a value of the given field type from its dumped form.

Functions

dump(struct)

@spec dump(struct()) :: map()

Dump a struct to a map with string keys.

dump_value(type, value)

@spec dump_value(term(), term()) :: term()

Dump a value of the given field type to a JSON-ready term.

load(module, map)

@spec load(module(), map()) :: struct()

Rebuild a sealed struct of module from a dumped map (string or atom keys).

load_value(type, value)

@spec load_value(term(), term()) :: term()

Load a value of the given field type from its dumped form.