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.

example

Example

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

Link to this section Summary

Functions

Converts value to a JSON-encodable type.

Link to this section Types

Link to this section Functions

Converts value to a JSON-encodable type.