michalmuskala / jason

A blazing fast JSON parser and generator in pure Elixir.
Other
1.61k stars 169 forks source link

Jason.Decoder is not a protocol #150

Closed amplexdenmark closed 2 years ago

amplexdenmark commented 2 years ago

Hi

I'm trying to change code that uses Poison into using Jason.

And has come upon constructs like this: defimpl Poison.Decoder, for: CMSAPI.Model.Attribute do def decode(value, _options) do ... Just replacing Poison with Jason in this snippet leads to this compile error: ** (ArgumentError) Jason.Decoder is not a protocol

Now looking at the code for 'Jason.Decoder' sure enough it is not a protocol, but Jason.Encoder is.

Is this deliberate? or an oversight?

Do you have a suggestion to the easiest way for me to move forward?

Best Søren

michalmuskala commented 2 years ago

Yes. Jason does not support decoding directly into data structures - this is one of the biggest differences to Poison that we call-out in the README. This is usually better served by another library that can properly handle nested data structures and type validation, such as Ecto.Changeset, Vex, Norm, or any similar.