Response.fromJson constructor

Response.fromJson(
  1. Map<String, Object?> json
)

Initialize a newly created instance based on the given JSON data.

Implementation

factory Response.fromJson(Map<String, Object?> json) {
  var id = json[ID];
  if (id is! String) {
    throw StateError('Unexpected type for id');
  }

  RequestError? decodedError;
  var error = json[ERROR];
  if (error is Map) {
    decodedError =
        RequestError.fromJson(ResponseDecoder(null), '.error', error);
  }

  var requestTime = json[REQUEST_TIME];
  if (requestTime is! int) {
    throw StateError('Unexpected type for requestTime');
  }

  Map<String, Object?>? decodedResult;
  var result = json[Response.RESULT];
  if (result is Map<String, Object?>) {
    decodedResult = result;
  }

  return Response(id, requestTime,
      error: decodedError, result: decodedResult);
}