asList method

List asList ()

Returns decoded data as List if decoding has already occurred.

If decoding has not yet occurred, this method throws an HTTPBodyDecoderException.

If decoding as occurred, behavior is the same as decodeAsList, but the result is not wrapped in Future.

Implementation

List<dynamic> asList() {
  if (!hasBeenDecoded) {
    throw new HTTPBodyDecoderException(
        "asList() invoked, but has not been decoded yet.");
  }

  if (_decodedData == null) {
    return null;
  }

  if (_decodedData.length != 1) {
    throw new HTTPBodyDecoderException(
        "decodeAsList() failed: more than one object in 'decodedData'.");
  }

  var firstObject = _decodedData.first;
  if (firstObject is! List) {
    throw new HTTPBodyDecoderException("asList() invoked on non-List data.");
  }

  return firstObject;
}