View Source Jsonrs.Encoder protocol (jsonrs v0.3.3)

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 your 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

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

Summary

Functions

Converts value to a JSON-encodable type.

Types

Functions

Converts value to a JSON-encodable type.