fromJson static method

PubSubCommentBase? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static PubSubCommentBase? 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 "PubSubCommentBase[_id]" is missing from JSON.');
      assert(json[r'_id'] != null, 'Required key "PubSubCommentBase[_id]" has a null value in JSON.');
      assert(json.containsKey(r'tenantId'), 'Required key "PubSubCommentBase[tenantId]" is missing from JSON.');
      assert(json[r'tenantId'] != null, 'Required key "PubSubCommentBase[tenantId]" has a null value in JSON.');
      assert(json.containsKey(r'urlId'), 'Required key "PubSubCommentBase[urlId]" is missing from JSON.');
      assert(json[r'urlId'] != null, 'Required key "PubSubCommentBase[urlId]" has a null value in JSON.');
      assert(json.containsKey(r'commenterName'), 'Required key "PubSubCommentBase[commenterName]" is missing from JSON.');
      assert(json[r'commenterName'] != null, 'Required key "PubSubCommentBase[commenterName]" has a null value in JSON.');
      assert(json.containsKey(r'commentHTML'), 'Required key "PubSubCommentBase[commentHTML]" is missing from JSON.');
      assert(json[r'commentHTML'] != null, 'Required key "PubSubCommentBase[commentHTML]" has a null value in JSON.');
      assert(json.containsKey(r'comment'), 'Required key "PubSubCommentBase[comment]" is missing from JSON.');
      assert(json[r'comment'] != null, 'Required key "PubSubCommentBase[comment]" has a null value in JSON.');
      assert(json.containsKey(r'verified'), 'Required key "PubSubCommentBase[verified]" is missing from JSON.');
      assert(json[r'verified'] != null, 'Required key "PubSubCommentBase[verified]" has a null value in JSON.');
      assert(json.containsKey(r'url'), 'Required key "PubSubCommentBase[url]" is missing from JSON.');
      assert(json[r'url'] != null, 'Required key "PubSubCommentBase[url]" has a null value in JSON.');
      assert(json.containsKey(r'approved'), 'Required key "PubSubCommentBase[approved]" is missing from JSON.');
      assert(json[r'approved'] != null, 'Required key "PubSubCommentBase[approved]" has a null value in JSON.');
      assert(json.containsKey(r'locale'), 'Required key "PubSubCommentBase[locale]" is missing from JSON.');
      return true;
    }());

    return PubSubCommentBase(
      id: mapValueOfType<String>(json, r'_id')!,
      tenantId: mapValueOfType<String>(json, r'tenantId')!,
      userId: mapValueOfType<String>(json, r'userId'),
      urlId: mapValueOfType<String>(json, r'urlId')!,
      commenterName: mapValueOfType<String>(json, r'commenterName')!,
      commenterLink: mapValueOfType<String>(json, r'commenterLink'),
      commentHTML: mapValueOfType<String>(json, r'commentHTML')!,
      comment: mapValueOfType<String>(json, r'comment')!,
      parentId: mapValueOfType<String>(json, r'parentId'),
      votes: mapValueOfType<int>(json, r'votes'),
      votesUp: mapValueOfType<int>(json, r'votesUp'),
      votesDown: mapValueOfType<int>(json, r'votesDown'),
      verified: mapValueOfType<bool>(json, r'verified')!,
      avatarSrc: mapValueOfType<String>(json, r'avatarSrc'),
      hasImages: mapValueOfType<bool>(json, r'hasImages'),
      hasLinks: mapValueOfType<bool>(json, r'hasLinks'),
      isByAdmin: mapValueOfType<bool>(json, r'isByAdmin'),
      isByModerator: mapValueOfType<bool>(json, r'isByModerator'),
      isPinned: mapValueOfType<bool>(json, r'isPinned'),
      isLocked: mapValueOfType<bool>(json, r'isLocked'),
      displayLabel: mapValueOfType<String>(json, r'displayLabel'),
      rating: mapValueOfType<double>(json, r'rating'),
      badges: CommentUserBadgeInfo.listFromJson(json[r'badges']),
      viewCount: mapValueOfType<int>(json, r'viewCount'),
      isDeleted: mapValueOfType<bool>(json, r'isDeleted'),
      isDeletedUser: mapValueOfType<bool>(json, r'isDeletedUser'),
      isSpam: mapValueOfType<bool>(json, r'isSpam'),
      anonUserId: mapValueOfType<String>(json, r'anonUserId'),
      feedbackIds: json[r'feedbackIds'] is Iterable
          ? (json[r'feedbackIds'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      flagCount: mapValueOfType<int>(json, r'flagCount'),
      domain: mapValueOfType<String>(json, r'domain'),
      url: mapValueOfType<String>(json, r'url')!,
      pageTitle: mapValueOfType<String>(json, r'pageTitle'),
      expireAt: mapDateTime(json, r'expireAt', r''),
      reviewed: mapValueOfType<bool>(json, r'reviewed'),
      hasCode: mapValueOfType<bool>(json, r'hasCode'),
      approved: mapValueOfType<bool>(json, r'approved')!,
      locale: mapValueOfType<String>(json, r'locale'),
      isBannedUser: mapValueOfType<bool>(json, r'isBannedUser'),
      groupIds: json[r'groupIds'] is Iterable
          ? (json[r'groupIds'] as Iterable).cast<String>().toList(growable: false)
          : const [],
    );
  }
  return null;
}