Skip to content

Commit

Permalink
define sanitize_map function for formatting map/structs correctly #1
Browse files Browse the repository at this point in the history
  • Loading branch information
RobStallion committed Aug 3, 2017
1 parent b9d58b5 commit 5b6bd64
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/epjs_app/encoder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@ defmodule EpjsApp.Encoder do
Enum.map(list, &sanitize_map/1)
end

def sanitize_map(nil) do
nil
end

def sanitize_map(map) do
map
|> Map.from_struct
|> Map.drop([:__meta__, :__struct__])
if Map.has_key?(map, :__struct__) do
map
|> Map.from_struct
|> Map.drop([:__meta__, :__struct__])
else
map
end
end
end

0 comments on commit 5b6bd64

Please sign in to comment.