findDecoder function

dynamic findDecoder(
  1. Type type,
  2. Map<Type, dynamic> decoders
)

Returns the decoder for type in decoders, or null if there is none.

An entry for type wins. Otherwise a NyDecoder registered for T, such as Decode or OneOf, also decodes List<T>. Last come the built-in decoders for plain JSON types such as Map<String, dynamic>.

Implementation

dynamic findDecoder(Type type, Map<Type, dynamic> decoders) {
  if (decoders.containsKey(type)) return decoders[type];
  for (final Object? decoder in decoders.values) {
    if (decoder is NyDecoder && decoder.listType == type) {
      return decoder.listDecoder;
    }
  }
  return _jsonDecoders[type];
}