fromJson static method

APISSOUser? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static APISSOUser? 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'id'), 'Required key "APISSOUser[id]" is missing from JSON.');
      assert(json[r'id'] != null, 'Required key "APISSOUser[id]" has a null value in JSON.');
      assert(json.containsKey(r'username'), 'Required key "APISSOUser[username]" is missing from JSON.');
      assert(json[r'username'] != null, 'Required key "APISSOUser[username]" has a null value in JSON.');
      assert(json.containsKey(r'websiteUrl'), 'Required key "APISSOUser[websiteUrl]" is missing from JSON.');
      assert(json[r'websiteUrl'] != null, 'Required key "APISSOUser[websiteUrl]" has a null value in JSON.');
      assert(json.containsKey(r'email'), 'Required key "APISSOUser[email]" is missing from JSON.');
      assert(json[r'email'] != null, 'Required key "APISSOUser[email]" has a null value in JSON.');
      assert(json.containsKey(r'signUpDate'), 'Required key "APISSOUser[signUpDate]" is missing from JSON.');
      assert(json[r'signUpDate'] != null, 'Required key "APISSOUser[signUpDate]" has a null value in JSON.');
      assert(json.containsKey(r'createdFromUrlId'), 'Required key "APISSOUser[createdFromUrlId]" is missing from JSON.');
      assert(json[r'createdFromUrlId'] != null, 'Required key "APISSOUser[createdFromUrlId]" has a null value in JSON.');
      assert(json.containsKey(r'loginCount'), 'Required key "APISSOUser[loginCount]" is missing from JSON.');
      assert(json[r'loginCount'] != null, 'Required key "APISSOUser[loginCount]" has a null value in JSON.');
      assert(json.containsKey(r'avatarSrc'), 'Required key "APISSOUser[avatarSrc]" is missing from JSON.');
      assert(json[r'avatarSrc'] != null, 'Required key "APISSOUser[avatarSrc]" has a null value in JSON.');
      assert(json.containsKey(r'optedInNotifications'), 'Required key "APISSOUser[optedInNotifications]" is missing from JSON.');
      assert(json[r'optedInNotifications'] != null, 'Required key "APISSOUser[optedInNotifications]" has a null value in JSON.');
      assert(json.containsKey(r'optedInSubscriptionNotifications'), 'Required key "APISSOUser[optedInSubscriptionNotifications]" is missing from JSON.');
      assert(json[r'optedInSubscriptionNotifications'] != null, 'Required key "APISSOUser[optedInSubscriptionNotifications]" has a null value in JSON.');
      assert(json.containsKey(r'displayLabel'), 'Required key "APISSOUser[displayLabel]" is missing from JSON.');
      assert(json[r'displayLabel'] != null, 'Required key "APISSOUser[displayLabel]" has a null value in JSON.');
      assert(json.containsKey(r'displayName'), 'Required key "APISSOUser[displayName]" is missing from JSON.');
      assert(json[r'displayName'] != null, 'Required key "APISSOUser[displayName]" has a null value in JSON.');
      return true;
    }());

    return APISSOUser(
      id: mapValueOfType<String>(json, r'id')!,
      username: mapValueOfType<String>(json, r'username')!,
      websiteUrl: mapValueOfType<String>(json, r'websiteUrl')!,
      email: mapValueOfType<String>(json, r'email')!,
      signUpDate: mapValueOfType<int>(json, r'signUpDate')!,
      createdFromUrlId: mapValueOfType<String>(json, r'createdFromUrlId')!,
      loginCount: mapValueOfType<int>(json, r'loginCount')!,
      avatarSrc: mapValueOfType<String>(json, r'avatarSrc')!,
      optedInNotifications: mapValueOfType<bool>(json, r'optedInNotifications')!,
      optedInSubscriptionNotifications: mapValueOfType<bool>(json, r'optedInSubscriptionNotifications')!,
      displayLabel: mapValueOfType<String>(json, r'displayLabel')!,
      displayName: mapValueOfType<String>(json, r'displayName')!,
      isAccountOwner: mapValueOfType<bool>(json, r'isAccountOwner'),
      isAdminAdmin: mapValueOfType<bool>(json, r'isAdminAdmin'),
      isCommentModeratorAdmin: mapValueOfType<bool>(json, r'isCommentModeratorAdmin'),
      isProfileActivityPrivate: mapValueOfType<bool>(json, r'isProfileActivityPrivate'),
      isProfileCommentsPrivate: mapValueOfType<bool>(json, r'isProfileCommentsPrivate'),
      isProfileDMDisabled: mapValueOfType<bool>(json, r'isProfileDMDisabled'),
      hasBlockedUsers: mapValueOfType<bool>(json, r'hasBlockedUsers'),
      groupIds: json[r'groupIds'] is Iterable
          ? (json[r'groupIds'] as Iterable).cast<String>().toList(growable: false)
          : const [],
    );
  }
  return null;
}