Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserializing as MapSet fails with BadMapError #187

janpieper opened this issue May 23, 2019 · 0 comments


None yet
1 participant
Copy link

commented May 23, 2019

Poison encodes a MapSet into a list:

iex>[1, 2, 3]) |> Poison.encode!()

But when trying to deserialize a JSON list as a MapSet, it fails:

iex> "[1,2,3]" |> Poison.decode!(as: %MapSet{})
** (BadMapError) expected a map, got: [1, 2, 3]
    (elixir) lib/map.ex:437: Map.get([1, 2, 3], "map", %{})
    (poison) lib/poison/decoder.ex:73: anonymous fn/3 in Poison.Decode.transform_struct/4
    (stdlib) maps.erl:232: :maps.fold_1/3
    (poison) lib/poison/decoder.ex:72: Poison.Decode.transform_struct/4
    (poison) lib/poison.ex:87: Poison.decode!/2

The reason for the BadMapError is, that Poison tries to deserialize it as a simple struct, which is a map, not a list:

defp transform(value, keys, %{__struct__: _} = as, options) do
transform_struct(value, keys, as, options)

I am wondering if Poison should implement a special handling for deserializing a MapSet to avoid this error, because MapSet is more or less a list, not a map.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.