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