View Source Jsonrs.Encoder protocol (jsonrs v0.3.2)
Protocol controlling how a value is encoded to JSON.
By default, structs are encoded as maps without the
:__struct__ key. If this
is sufficient for you use, you don't need to implement this protocol.
When implementing an encoding function, the goal is to turn your value into something already capable of being encoded.
An implementation of this protocol for
Decimal might look something like
defimpl Jsonrs.Encoder, for: Decimal do def encode(value) do Decimal.to_string(value) end end
Which will cause the Decimal to be encoded as its string representation