The Finnternet Like the Internet but with more me

Fixing Poison Encode Error

In one of my Phoenix projects, I recently ran into the following error when attempting to return a struct returned from an Ecto query.

** (Poison.EncodeError) unable to encode value: {nil, "users"}

The reason for this error is because of the meta field included in the Ecto record struct. Thankfully this leads to a simple solution.

Add a derive annotation to your schemas and specify the fields you want to return.

@derive {Poison.Encoder, only: [:field1, :field2]}