Converts Elixir terms into JSON-safe values for storage in PostgreSQL JSONB columns.
Node results and errors go through this module before being persisted, which is why nodes downstream see string keys and string values where atoms were returned.
Summary
Functions
Recursively converts a term into a JSON-safe value.
Reverses wrap_result/1: returns the inner value of a %{"value" => value}
map, or the map itself otherwise.
Serializes a node result, wrapping non-map values as %{"value" => value}
so that every stored result is a JSON object.
Functions
Recursively converts a term into a JSON-safe value.
- map keys become strings (structs are converted to plain maps);
- atoms other than
nil,trueandfalsebecome strings; - tuples become lists;
- other values are returned unchanged.
Examples
iex> Sig.Serializer.serialize(%{status: :ok, pair: {1, :a}})
%{"status" => "ok", "pair" => [1, "a"]}
Reverses wrap_result/1: returns the inner value of a %{"value" => value}
map, or the map itself otherwise.
Examples
iex> Sig.Serializer.unwrap_result(%{"value" => 42})
42
iex> Sig.Serializer.unwrap_result(%{"total" => 3})
%{"total" => 3}
Serializes a node result, wrapping non-map values as %{"value" => value}
so that every stored result is a JSON object.
Examples
iex> Sig.Serializer.wrap_result(%{total: 3})
%{"total" => 3}
iex> Sig.Serializer.wrap_result(:done)
%{"value" => "done"}