mapOf<T> method
Returns a Map of T
or null
if rawValue is not a Map of T
If actual data is not a Map of T
, calls builder
to get one
Implementation
Map<String, T>? mapOf<T>([T? Function(dynamic)? builder]) {
if (_rawValue is Map) {
try {
return (_rawValue as Map).map<String, T>((dynamic key, dynamic value) {
if (key is! String) {
exception = exception ?? JsonException(JsonError.wrongType, userReason: 'JSON Error: key must be a String');
throw exception!;
} else if (value is T) {
return MapEntry<String, T>(key, value);
} else if (builder != null) {
T? built = builder(value);
if (built != null) {
return MapEntry<String, T>(key, built);
}
}
exception = exception ??
JsonException(JsonError.wrongType, userReason: 'JSON Error: at least one element is not of type `$T`');
throw exception!;
});
} on JsonException catch (_) {
return null;
}
}
return null;
}