deserializeBodyAsync<T extends Object> method

Future<T?> deserializeBodyAsync<T extends Object>()

Returns T by deserializing the response body to it. The response is deserialized asynchronously in an isolate.

For small response body, try RestResponse.deserializeBody.

Implementation

Future<T?> deserializeBodyAsync<T extends Object>() async {
  if (!serializer.contains<T>()) {
    throw ClientException('No serializers found for type `$T`.');
  }
  if ($HandleFeatures.disableAsyncDeserializationWithHandle &&
      didUseHandle(this)) {
    return deserializeBody();
  }
  try {
    return await serializer.deserializeAsync<T>(body);
  } catch (e, s) {
    // Todo: Replace with `Error.throwWithStackTrace(error, stackTrace);` in SDK 2.16.0.
    throw RestResponseException(
      'Failed to deserialize body asynchronously',
      uri: request?.url,
      innerException: e,
      innerStackTrace: s,
    );
  }
}