JSON codec indirection.
JSON needs no dependency of its own. The codec is resolved, once, in this order:
- the module configured as
config :typedb, :json_codec, MyCodec TypeDB.JSON.Native, backed by the built-inJSONmodule
In practice the list ends there. This driver requires Elixir 1.18, every
version of which has the built-in JSON, so step 2 always matches and
TypeDB.JSON.Jason is only ever reached by configuring it:
config :typedb, :json_codec, TypeDB.JSON.Jasonresolve!/0 still falls back to Jason and then to an error below step 2.
Neither can execute while the Elixir floor is 1.18, and both are kept because
they are unreachable owing to that floor rather than to being wrong — deleting
them would turn a future change of floor into a silent change of behaviour.
A codec is any module implementing this behaviour.
Summary
Callbacks
Decodes a JSON binary. Returns {:error, reason} on malformed input.
Encodes a term to JSON iodata. Raises on unencodable input.
Functions
Returns the resolved codec module.
Decodes a JSON binary.
Encodes term to a JSON binary.
Encodes term to JSON iodata.
Forgets the memoised codec. Intended for tests.
Callbacks
Functions
@spec codec() :: module()
Returns the resolved codec module.
The result is memoised in :persistent_term. Change :json_codec before the
first call, or call reset/0 afterwards.
Decodes a JSON binary.
Encodes term to a JSON binary.
Encodes term to JSON iodata.
@spec reset() :: :ok
Forgets the memoised codec. Intended for tests.