View Source Estructura.Flattenable protocol (estructura v1.6.0)
Summary
Functions
The function returning the flattened input.
Types
@type t() :: term()
All the types that implement this protocol.
Functions
The function returning the flattened input.
This protocol is explicitly handful when deeply nested structs are to be serialized.
iex|%_{}|1 ▶ %Estructura.User{}
%Estructura.User{
address: %Estructura.User.Address{
city: nil,
street: %Estructura.User.Address.Street{house: nil, name: []}
},
data: %Estructura.User.Data{age: nil},
name: nil
}
iex|%_{}|2 ▶ Estructura.Flattenable.flatten(%Estructura.User{}, coupler: "-", except: ~w|address-street data-age|)
%{"address-city" => nil, "birthday" => nil, "created_at" => nil, "name" => nil}
iex|%_{}|3 ▶ Estructura.Flattenable.flatten(%Estructura.User{}, only: ~w|address_street data_age|)
%{"address_street_house" => nil, "data_age" => nil}
iex|%_{}|4 ▶ Estructura.Flattenable.flatten(%Estructura.User{}, only: ~w|address|)
%{"address_city" => nil, "address_street_house" => nil}
Allowed options are:
coupler
the string to concatenate nested keys with, default:-
only
the list of keys to selectexcept
the list of keys to ignorejsonify
true
or a json encoder implementation; if set, the values will be jsonified
To enable it for your struct, use @derive Estructura.Flattenable
or
@derive {Estructura.Flattenable, options}
. Estructura
implementations derive it be default.