fromObject<N, E> static method

EncodableValue fromObject<N, E>(
  1. N value, {
  2. ObjectEncoder<N, E>? encoder,
})

Creates an EncodableValue from value.

value is not supposed to be directly encodable. As such, encoder is used to convert it to an encodable object.

If encoder is omitted, the result of calling .toJson() on value will be used.

Throws a JsonPreparationError if:

  • encoder is provided, but E could not represent an encodable object.
  • value does not have a callable .toJson() method.
  • E does not match the .toJson() result type.

Implementation

static EncodableValue fromObject<N, E>(N value,
    {ObjectEncoder<N, E>? encoder}) {
  return EncodableValue._(prepareObject<N, E>(value, encoder));
}