Skip to content

Latest commit

 

History

History
57 lines (39 loc) · 1.44 KB

README.md

File metadata and controls

57 lines (39 loc) · 1.44 KB

Maptu

Build Status Hex.pm

Maptu is a small Elixir library that provides functions to convert from "encoded" maps to Elixir structs.

"Encoded" maps are maps/structs that have been encoded through some protocol (like MessagePack or JSON) decoded back from that protocol. In the case of structs, the information about the struct is lost, usually like this:

%URI{port: 8080} |> encode() |> decode()
#=> %{"__struct__" => "Elixir.URI", "port" => 8080}

Maptu's job is to get that map with string keys back to an Elixir struct in a safe way (to avoid memory leaks coming from mindlessly converting string keys to atoms):

%URI{port: 8080} |> encode() |> decode() |> Maptu.struct!()
#=> %URI{port: 8080}

Credit

Most of the design and implementation ideas in this library come from the awesome @lexmag ❤️

Installation

Add :maptu to your list of dependencies in mix.exs:

def deps do
  [{:maptu, "~> 1.0"}]
end

and be sure to add :maptu to your list of started applications:

def application do
  [applications: [:maptu]]
end

Documentation is available on Hex.

License

MIT © 2016 Andrea Leopardi, Aleksei Magusev (license file)