decodeObject<T> method

  1. @override
T decodeObject<T>({
  1. Decodable<T>? using,
})
override

Decodes the data as an object of type T.

This forwards the decoding to the provided Decodable implementation. Otherwise tries to decode the data to a supported primitive type T.

This should only be called if the format returned a DecodingType<T> from whatsNext or is otherwise known to support T as a custom type.

Implementation

@override
T decodeObject<T>({Decodable<T>? using}) {
  try {
    if (using != null) {
      return using.decode(this);
    }
    final delegate = _customTypes.whereType<CustomTypeDelegate<T>>().firstOrNull;
    if (delegate != null) {
      return delegate.decode(this);
    }
    return _value as T;
  } catch (e, st) {
    Error.throwWithStackTrace(CodableException.wrap(e, method: 'decode', hint: '$T'), st);
  }
}