fromJson static method

InitChunkedUploadResponse? fromJson(
  1. dynamic value
)

Returns a new InitChunkedUploadResponse instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static InitChunkedUploadResponse? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      assert(json.containsKey(r'sessionId'), 'Required key "InitChunkedUploadResponse[sessionId]" is missing from JSON.');
      assert(json[r'sessionId'] != null, 'Required key "InitChunkedUploadResponse[sessionId]" has a null value in JSON.');
      assert(json.containsKey(r'blocksToUpload'), 'Required key "InitChunkedUploadResponse[blocksToUpload]" is missing from JSON.');
      assert(json[r'blocksToUpload'] != null, 'Required key "InitChunkedUploadResponse[blocksToUpload]" has a null value in JSON.');
      assert(json.containsKey(r'blocksAlreadyExist'), 'Required key "InitChunkedUploadResponse[blocksAlreadyExist]" is missing from JSON.');
      assert(json[r'blocksAlreadyExist'] != null, 'Required key "InitChunkedUploadResponse[blocksAlreadyExist]" has a null value in JSON.');
      assert(json.containsKey(r'deduplicationPct'), 'Required key "InitChunkedUploadResponse[deduplicationPct]" is missing from JSON.');
      assert(json[r'deduplicationPct'] != null, 'Required key "InitChunkedUploadResponse[deduplicationPct]" has a null value in JSON.');
      assert(json.containsKey(r'estimatedUploadSize'), 'Required key "InitChunkedUploadResponse[estimatedUploadSize]" is missing from JSON.');
      assert(json[r'estimatedUploadSize'] != null, 'Required key "InitChunkedUploadResponse[estimatedUploadSize]" has a null value in JSON.');
      return true;
    }());

    return InitChunkedUploadResponse(
      sessionId: mapValueOfType<String>(json, r'sessionId')!,
      blocksToUpload: json[r'blocksToUpload'] is Iterable
          ? (json[r'blocksToUpload'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      blocksAlreadyExist: json[r'blocksAlreadyExist'] is Iterable
          ? (json[r'blocksAlreadyExist'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      deduplicationPct: mapValueOfType<double>(json, r'deduplicationPct')!,
      estimatedUploadSize: mapValueOfType<int>(json, r'estimatedUploadSize')!,
    );
  }
  return null;
}