fromEJson<T> function

T fromEJson<T>(
  1. EJsonValue? ejson
)

Converts ejson to type T.

Throws InvalidEJson if ejson is not valid for T. Throws MissingDecoder if no decoder is registered for T.

Implementation

T fromEJson<T>(EJsonValue ejson) {
  final type = T;
  final nullable = type.isNullable;
  final decoder = nullable ? _decodeNullable : _decoders[type.base];
  if (decoder == null) {
    throw MissingDecoder._(ejson, type);
  }
  final args = nullable ? [type.nonNull] : type.args;
  if (args.isEmpty) {
    return decoder(ejson) as T; // minor optimization
  }
  return decoder.callWith(typeArguments: args, parameters: [ejson]) as T;
}