State of Elixir 2024 Results
:ok
:results_loaded
** (Protocol.UndefinedError) protocol Jason.Encoder not implemented for %{state: :loaded, context: nil, prefix: nil, source: "responses", __struct__: Ecto.Schema.Metadata, schema: StateOfElixir.Response} of type Ecto.Schema.Metadata (a struct), Jason.Encoder protocol must always be explicitly implemented.
If you own the struct, you can derive the implementation specifying which fields should be encoded to JSON:
@derive {Jason.Encoder, only: [....]}
defstruct ...
It is also possible to encode all fields, although this should be used carefully to avoid accidentally leaking private information when new fields are added:
@derive Jason.Encoder
defstruct ...
Finally, if you don't own the struct you want to encode to JSON, you may use Protocol.derive/3 placed outside of any module:
Protocol.derive(Jason.Encoder, NameOfTheStruct, only: [...])
Protocol.derive(Jason.Encoder, NameOfTheStruct)
. This protocol is implemented for the following type(s): Any, Atom, BitString, Date, DateTime, Decimal, Float, Integer, Jason.Fragment, Jason.OrderedObject, List, Map, NaiveDateTime, Time
(jason 1.4.1) lib/jason.ex:164: Jason.encode!/2
#cell:kktnkhbliyquiqcly3h2sielad45gk2z:7: (file)
Something went wrong