Skip to content

Commit

Permalink
Store non string binaries as list of integer (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
rschef authored Apr 22, 2021
1 parent e4c56ce commit 6ab8b29
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/paper_trail/serializer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ defmodule PaperTrail.Serializer do
dumped_value =
if(
type in ignored_ecto_types(),
do: value,
do: serialize_binary(value),
else: do_dump_field!(schema, field, type, value, adapter)
)

Expand Down Expand Up @@ -234,4 +234,15 @@ defmodule PaperTrail.Serializer do

@spec get_env(atom, any) :: any
defp get_env(key, default), do: Application.get_env(:paper_trail, key, default)

@spec serialize_binary(binary()) :: String.t() | [integer()]
defp serialize_binary(binary) when is_binary(binary) do
if String.valid?(binary) do
binary
else
:binary.bin_to_list(binary)
end
end

defp serialize_binary(value), do: value
end

0 comments on commit 6ab8b29

Please sign in to comment.