Encoding Ecto Structs into JSON

Today we're just going to solve one problem—encoding an Ecto struct into JSON with Poison.

Out of the box, Poison can't encode Ecto's __meta__ fields, so they'll need to be dropped before encoding into JSON. The same is true for unloaded associations. There are a few ways to do this, but using @derive in the struct's definition to implement the Poison.Encoder protocol is the cleanest way.

Back to index

No Comments