cereal v1.0.0 Cereal.Serializer View Source

The Serializer for defining serializers in an opionated way that isn’t as complex or verbose as JSON API.

Usage example:

defmodule PostSerializer do

use Cereal.Serializer

attributes [:id, :name, :published_state]
has_one :author, serializer: AuthorSerializer

def published_state(entity) do
  entity.published_at
  |> case do
    true  -> "published"
    false -> "draft"
  end
end

end

Link to this section Summary

Link to this section Functions

Link to this macro attributes(attrs) View Source (macro)
Link to this macro embeds_one(name, opts) View Source (macro)
Link to this macro has_many(name, opts) View Source (macro)
Link to this macro has_one(name, opts) View Source (macro)