mapGuarded<T> function
A convenience method to map a JSON object to a Dart object with error handling.
Implementation
T? mapGuarded<T>({
required T Function(Map<String, dynamic> json) mapper,
required dynamic json,
}) {
if (json == null || json is! Map<String, dynamic>) {
return null;
}
try {
return mapper(json);
} catch (_) {
return null;
}
}