decodeMapTyped<T extends Map<String, V>?, V> function
T
decodeMapTyped<
T extends Map<String, V>?, V>( - dynamic raw, {
- String? name,
})
Implementation
T decodeMapTyped<T extends Map<String, V>?, V>(dynamic raw, {String? name}) {
if (raw is T) {
return raw;
} else if (raw is Map<String, dynamic>) {
final codec = TransferCodec.find<V>();
return raw.map((key, value) => MapEntry(
key,
decodeTyped<V>(value,
codec: codec, name: name?.apply((n) => '$n.$key')))) as T;
} else if (TypeCheck<T>().isNullable && raw == null) {
return null as T;
} else if (raw is Map && raw.isEmpty) {
return <String, V>{} as T;
} else {
throw CodecException.typeMismatch(T, raw.runtimeType, name);
}
}