fromJson static method

APICommentBase? fromJson(
  1. dynamic value
)

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

Implementation

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

    return APICommentBase(
      id: mapValueOfType<String>(json, r'id')!,
      aiDeterminedSpam: mapValueOfType<bool>(json, r'aiDeterminedSpam'),
      anonUserId: mapValueOfType<String>(json, r'anonUserId'),
      approved: mapValueOfType<bool>(json, r'approved')!,
      avatarSrc: mapValueOfType<String>(json, r'avatarSrc'),
      badges: CommentUserBadgeInfo.listFromJson(json[r'badges']),
      comment: mapValueOfType<String>(json, r'comment')!,
      commentHTML: mapValueOfType<String>(json, r'commentHTML')!,
      commenterEmail: mapValueOfType<String>(json, r'commenterEmail'),
      commenterLink: mapValueOfType<String>(json, r'commenterLink'),
      commenterName: mapValueOfType<String>(json, r'commenterName')!,
      date: mapDateTime(json, r'date', r''),
      displayLabel: mapValueOfType<String>(json, r'displayLabel'),
      domain: mapValueOfType<String>(json, r'domain'),
      externalId: mapValueOfType<String>(json, r'externalId'),
      externalParentId: mapValueOfType<String>(json, r'externalParentId'),
      expireAt: mapDateTime(json, r'expireAt', r''),
      feedbackIds: json[r'feedbackIds'] is Iterable
          ? (json[r'feedbackIds'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      flagCount: mapValueOfType<int>(json, r'flagCount'),
      fromProductId: mapValueOfType<int>(json, r'fromProductId'),
      hasCode: mapValueOfType<bool>(json, r'hasCode'),
      hasImages: mapValueOfType<bool>(json, r'hasImages'),
      hasLinks: mapValueOfType<bool>(json, r'hasLinks'),
      hashTags: CommentUserHashTagInfo.listFromJson(json[r'hashTags']),
      isByAdmin: mapValueOfType<bool>(json, r'isByAdmin'),
      isByModerator: mapValueOfType<bool>(json, r'isByModerator'),
      isDeleted: mapValueOfType<bool>(json, r'isDeleted'),
      isDeletedUser: mapValueOfType<bool>(json, r'isDeletedUser'),
      isPinned: mapValueOfType<bool>(json, r'isPinned'),
      isLocked: mapValueOfType<bool>(json, r'isLocked'),
      isSpam: mapValueOfType<bool>(json, r'isSpam'),
      localDateHours: mapValueOfType<int>(json, r'localDateHours'),
      localDateString: mapValueOfType<String>(json, r'localDateString'),
      locale: mapValueOfType<String>(json, r'locale'),
      mentions: CommentUserMentionInfo.listFromJson(json[r'mentions']),
      meta: APICommentBaseMeta.fromJson(json[r'meta']),
      moderationGroupIds: json[r'moderationGroupIds'] is Iterable
          ? (json[r'moderationGroupIds'] as Iterable).cast<String>().toList(growable: false)
          : const [],
      notificationSentForParent: mapValueOfType<bool>(json, r'notificationSentForParent'),
      notificationSentForParentTenant: mapValueOfType<bool>(json, r'notificationSentForParentTenant'),
      pageTitle: mapValueOfType<String>(json, r'pageTitle'),
      parentId: mapValueOfType<String>(json, r'parentId'),
      rating: mapValueOfType<double>(json, r'rating'),
      reviewed: mapValueOfType<bool>(json, r'reviewed'),
      tenantId: mapValueOfType<String>(json, r'tenantId')!,
      url: mapValueOfType<String>(json, r'url')!,
      urlId: mapValueOfType<String>(json, r'urlId')!,
      urlIdRaw: mapValueOfType<String>(json, r'urlIdRaw'),
      userId: mapValueOfType<String>(json, r'userId'),
      verified: mapValueOfType<bool>(json, r'verified')!,
      verifiedDate: mapDateTime(json, r'verifiedDate', r''),
      votes: mapValueOfType<int>(json, r'votes'),
      votesDown: mapValueOfType<int>(json, r'votesDown'),
      votesUp: mapValueOfType<int>(json, r'votesUp'),
    );
  }
  return null;
}