Skip to content

Instantly share code, notes, and snippets.

@mikebaldry
Created July 22, 2016 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikebaldry/5cf02da7fad2e64c565832d4ebdbee73 to your computer and use it in GitHub Desktop.
Save mikebaldry/5cf02da7fad2e64c565832d4ebdbee73 to your computer and use it in GitHub Desktop.
defmodule TestApp.Serializer do
defmacro __using__(_) do
quote do
defimpl Msgpax.Packer, for: __MODULE__ do
def transform(struct) do
type = String.replace_prefix(to_string(__MODULE__), "Elixir.Msgpax.Packer.TestApp.Data.", "")
Msgpax.Packer.Map.transform(Map.merge(Map.from_struct(struct), %{"__type" => type}))
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment