fromJson static method

GetVotesResponse? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static GetVotesResponse? 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'status'), 'Required key "GetVotesResponse[status]" is missing from JSON.');
      assert(json[r'status'] != null, 'Required key "GetVotesResponse[status]" has a null value in JSON.');
      assert(json.containsKey(r'appliedAuthorizedVotes'), 'Required key "GetVotesResponse[appliedAuthorizedVotes]" is missing from JSON.');
      assert(json[r'appliedAuthorizedVotes'] != null, 'Required key "GetVotesResponse[appliedAuthorizedVotes]" has a null value in JSON.');
      assert(json.containsKey(r'appliedAnonymousVotes'), 'Required key "GetVotesResponse[appliedAnonymousVotes]" is missing from JSON.');
      assert(json[r'appliedAnonymousVotes'] != null, 'Required key "GetVotesResponse[appliedAnonymousVotes]" has a null value in JSON.');
      assert(json.containsKey(r'pendingVotes'), 'Required key "GetVotesResponse[pendingVotes]" is missing from JSON.');
      assert(json[r'pendingVotes'] != null, 'Required key "GetVotesResponse[pendingVotes]" has a null value in JSON.');
      return true;
    }());

    return GetVotesResponse(
      status: APIStatus.fromJson(json[r'status'])!,
      appliedAuthorizedVotes: PublicVote.listFromJson(json[r'appliedAuthorizedVotes']),
      appliedAnonymousVotes: PublicVote.listFromJson(json[r'appliedAnonymousVotes']),
      pendingVotes: PublicVote.listFromJson(json[r'pendingVotes']),
    );
  }
  return null;
}