read<T> method

  1. @override
T read<T>(
  1. dynamic input, {
  2. String? typeName,
  3. required bool isNullable,
})
override

Implementation

@override
T read<T>(dynamic input, {String? typeName, required bool isNullable}) {
  typeName ??= '$T';
  if (isNullable && input == null) {
    if(null is T) {
      return null as T;
    };

    throw StateError("Found a null value, but expected a $typeName");
  }
  final factory = _readerFactories.map((e) => e(typeName!)).firstWhere(
        (element) => element != null,
        orElse: () => (dynamic input) => input,
      );

  if (input == null) {
    throw "Null value not allowed for type ${typeName}";
  }
  return factory!(input) as T;
}