Poison encodes a MapSet into a list:
iex> MapSet.new([1, 2, 3]) |> Poison.encode!()
"[1,2,3]"
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) |
|
end |
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.
Poison encodes a
MapSetinto a list:But when trying to deserialize a JSON list as a
MapSet, it fails:The reason for the
BadMapErroris, that Poison tries to deserialize it as a simple struct, which is a map, not a list:poison/lib/poison/decoder.ex
Lines 33 to 35 in ac89db9
I am wondering if Poison should implement a special handling for deserializing a
MapSetto avoid this error, becauseMapSetis more or less a list, not a map.