View Source AnyJson.Codec behaviour (AnyJson v0.1.0)

Defines the callbacks that the adapters must implement.

Link to this section Summary

Callbacks

Decodes a JSON value into an Elixir term. Returns a tuple with {:ok, term} or {:error, reason}.

Decodes a JSON value into an Elixir term. Raises an exception if any errors happend.

Encodes any value into a valid JSON. Returns a tuple with {:ok, json} or {:error, reason}.

Encodes any value into a valid JSON. Raises an exception if any errors happend.

Link to this section Callbacks

Link to this callback

decode(json, decode_opts)

View Source
@callback decode(json :: String.t(), decode_opts :: keyword()) ::
  {:ok, any()} | {:error, any()}

Decodes a JSON value into an Elixir term. Returns a tuple with {:ok, term} or {:error, reason}.

Link to this callback

decode!(json, decode_opts)

View Source
@callback decode!(json :: String.t(), decode_opts :: keyword()) :: any()

Decodes a JSON value into an Elixir term. Raises an exception if any errors happend.

Link to this callback

encode(term, encode_opts)

View Source
@callback encode(term :: any(), encode_opts :: keyword()) ::
  {:ok, String.t()} | {:error, any()}

Encodes any value into a valid JSON. Returns a tuple with {:ok, json} or {:error, reason}.

Link to this callback

encode!(term, encode_opts)

View Source
@callback encode!(term :: any(), encode_opts :: keyword()) :: String.t()

Encodes any value into a valid JSON. Raises an exception if any errors happend.