-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
A map with atoms for keys is not serialized/deserialized correctly:
iex(4)> x = %{foo: 42}
%{foo: 42}
iex(5)> y = JsonSerde.deserialize!(JsonSerde.serialize!(x))
%{"foo" => 42}
iex(6)> x.foo
42
iex(7)> y.foo
** (KeyError) key :foo not found in: %{"foo" => 42}
Atom keys in custom structs are handled correctly:
iex(7)> defmodule Foo do
...(7)> defstruct [:foo]
...(7)> end
{:module, Foo, ...
iex(8)> xx = %Foo{foo: 42}
%Foo{foo: 42}
iex(9)> yy = JsonSerde.deserialize!(JsonSerde.serialize!(xx))
%Foo{foo: 42}
iex(10)> xx.foo
42
iex(11)> yy.foo
42
Also, numerical keys are not handled correctly:
iex(4)> mat = %{0 => "a", 1 => "b"}
%{0 => "a", 1 => "b"}
iex(5)> mat2 = JsonSerde.deserialize!(JsonSerde.serialize!(mat))
%{"0" => "a", "1" => "b"}
iex(6)> mat[0]
"a"
iex(7)> mat2[0]
nil
It appears that only string keys are supported. Is there a way to get this to work?
bbalser
Metadata
Metadata
Assignees
Labels
No labels