poison icon indicating copy to clipboard operation
poison copied to clipboard

Duplicated call to Poison.Decoder.decode/2 when using Poison.decode/2 with %{as: struct}

Open jcomellas opened this issue 6 years ago • 0 comments

A call to Poison.decode!/2 with %{as: struct} as option ends up calling:

  1. Poison.Parser.parse!/2
  2. Poison.Decode.transform/2
  3. Poison.Decoder.decode/2

The problem is that Poison.Decode.transform/2 ends up calling Poison.Decoder.decode/2 here. This means that any call to Poison.decode!/2 with automatic conversion to a struct will always end up calling Poison.Decoder.decode/2 twice. My suggestion would be to remove the call to Poison.Decoder.decode/2 from do_transform_struct/4 but this breaks one test.

What would you suggest to avoid this problem?

jcomellas avatar Sep 18 '19 07:09 jcomellas