Kombu.Utils.JSON (Kombu v0.1.0)

Copy Markdown View Source

Extended JSON serialization utilities matching kombu.utils.json.

Supports Kombu's {"__type__": marker, "__value__": encoded} envelope for datetime, date, time, decimal, uuid, bytes, base64, and user-registered struct types.

Summary

Functions

Serialize an Elixir term to a JSON string using Kombu's extended type tags.

Deserialize a JSON string or binary into an Elixir term, applying object_hook to decode {"__type__": ..., "__value__": ...} envelopes.

Default object hook that decodes {"__type__": marker, "__value__": val} maps.

Reset and register the default Kombu extended JSON types.

Register a custom Elixir struct module for JSON serialization/deserialization.

Functions

dumps(term, opts \\ [])

@spec dumps(term(), keyword()) :: String.t()

Serialize an Elixir term to a JSON string using Kombu's extended type tags.

dumps!(term, opts \\ [])

@spec dumps!(term(), keyword()) :: String.t()

loads(data, opts \\ [])

@spec loads(binary() | list(), keyword()) :: term()

Deserialize a JSON string or binary into an Elixir term, applying object_hook to decode {"__type__": ..., "__value__": ...} envelopes.

loads!(data, opts \\ [])

@spec loads!(binary() | list(), keyword()) :: term()

object_hook(map)

@spec object_hook(map()) :: term()

Default object hook that decodes {"__type__": marker, "__value__": val} maps.

register_default_types()

Reset and register the default Kombu extended JSON types.

register_type(struct_module, marker, encoder, decoder \\ &Function.identity/1)

@spec register_type(module(), String.t() | nil, (term() -> term()), (term() -> term())) ::
  :ok

Register a custom Elixir struct module for JSON serialization/deserialization.

If marker is nil, the encoder output is not wrapped in {"__type__": ..., "__value__": ...}.