-
Notifications
You must be signed in to change notification settings - Fork 214
Open
Description
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!/2The reason for the BadMapError is, that Poison tries to deserialize it as a simple struct, which is a map, not a list:
Lines 33 to 35 in ac89db9
| 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.
szymonwartak
Metadata
Metadata
Assignees
Labels
No labels