Gleanex.Decoder (Gleanex v0.1.0)

Copy Markdown View Source

Turn decoded JSON into the structs described by the generated schemas.

Generated schema modules expose __fields__/1, a keyword list mapping each field to its type. This module walks that description to build structs, lists of structs and nested values.

Anything it cannot place is passed through untouched, so an outdated spec degrades to plain maps rather than losing data or crashing.

Summary

Functions

Decode value according to a generated type description.

Functions

decode(value, arg2)

@spec decode(term(), term()) :: term()

Decode value according to a generated type description.

Type forms

  • {Module, :t} - build that struct
  • [type] - a list of that type
  • {:union, types} - best effort, see below
  • anything else - returned unchanged

Unions are ambiguous by nature. For a map, the candidate struct sharing the most field names with the payload wins; ties go to the leftmost candidate. For everything else the value passes through.