XApiEx.Deserializer (x_api_ex v1.0.0)

Helper functions for deserializing responses into models

Summary

Functions

Update the provided model with a deserialization of a nested value

Decode a JSON string into a plain map or list.

Decode a JSON string and convert the result into the given module's struct.

Functions

deserialize(model, field, atom, module)

@spec deserialize(
  struct(),
  atom(),
  :date | :datetime | :list | :map | :struct,
  module()
) :: struct()

Update the provided model with a deserialization of a nested value

json_decode(json)

@spec json_decode(String.t()) :: {:ok, term()} | {:error, term()}

Decode a JSON string into a plain map or list.

Parameters

  • json (String.t): A JSON-encoded string.

Returns

  • {:ok, term} on success
  • {:error, term} on failure

json_decode(json, module)

@spec json_decode(String.t(), module()) :: {:ok, struct()} | {:error, term()}

Decode a JSON string and convert the result into the given module's struct.

Parameters

  • json (String.t): A JSON-encoded string.
  • module (module): The module to decode the parsed value into.

Returns

  • {:ok, struct} on success
  • {:error, term} on failure