decodeList<E extends Object> method

List<E> decodeList<E extends Object>(
  1. String jsonPath,
  2. Object? json,
  3. JsonDecoderCallback<E> decoder
)
inherited

Decode a JSON object that is expected to be a List. The decoder is used to decode the items in the list.

The type parameter E is the expected type of the elements in the list.

Implementation

List<E> decodeList<E extends Object>(
    String jsonPath, Object? json, JsonDecoderCallback<E> decoder) {
  if (json == null) {
    return <E>[];
  } else if (json is List) {
    var result = <E>[];
    for (var i = 0; i < json.length; i++) {
      result.add(decoder('$jsonPath[$i]', json[i]));
    }
    return result;
  } else {
    throw mismatch(jsonPath, 'List', json);
  }
}