fromJson static method
Returns a new CommentData instance and imports its values from
value if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static CommentData? 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'commenterName'), 'Required key "CommentData[commenterName]" is missing from JSON.');
assert(json[r'commenterName'] != null, 'Required key "CommentData[commenterName]" has a null value in JSON.');
assert(json.containsKey(r'comment'), 'Required key "CommentData[comment]" is missing from JSON.');
assert(json[r'comment'] != null, 'Required key "CommentData[comment]" has a null value in JSON.');
assert(json.containsKey(r'url'), 'Required key "CommentData[url]" is missing from JSON.');
assert(json[r'url'] != null, 'Required key "CommentData[url]" has a null value in JSON.');
assert(json.containsKey(r'urlId'), 'Required key "CommentData[urlId]" is missing from JSON.');
assert(json[r'urlId'] != null, 'Required key "CommentData[urlId]" has a null value in JSON.');
return true;
}());
return CommentData(
date: mapValueOfType<int>(json, r'date'),
localDateString: mapValueOfType<String>(json, r'localDateString'),
localDateHours: mapValueOfType<int>(json, r'localDateHours'),
commenterName: mapValueOfType<String>(json, r'commenterName')!,
commenterEmail: mapValueOfType<String>(json, r'commenterEmail'),
commenterLink: mapValueOfType<String>(json, r'commenterLink'),
comment: mapValueOfType<String>(json, r'comment')!,
productId: mapValueOfType<int>(json, r'productId'),
userId: mapValueOfType<String>(json, r'userId'),
avatarSrc: mapValueOfType<String>(json, r'avatarSrc'),
parentId: mapValueOfType<String>(json, r'parentId'),
mentions: CommentUserMentionInfo.listFromJson(json[r'mentions']),
hashTags: CommentUserHashTagInfo.listFromJson(json[r'hashTags']),
pageTitle: mapValueOfType<String>(json, r'pageTitle'),
isFromMyAccountPage: mapValueOfType<bool>(json, r'isFromMyAccountPage'),
url: mapValueOfType<String>(json, r'url')!,
urlId: mapValueOfType<String>(json, r'urlId')!,
meta: mapValueOfType<Object>(json, r'meta'),
moderationGroupIds: json[r'moderationGroupIds'] is Iterable
? (json[r'moderationGroupIds'] as Iterable).cast<String>().toList(growable: false)
: const [],
rating: mapValueOfType<double>(json, r'rating'),
fromOfflineRestore: mapValueOfType<bool>(json, r'fromOfflineRestore'),
autoplayDelayMS: mapValueOfType<int>(json, r'autoplayDelayMS'),
feedbackIds: json[r'feedbackIds'] is Iterable
? (json[r'feedbackIds'] as Iterable).cast<String>().toList(growable: false)
: const [],
questionValues: GifSearchResponseImagesInnerInner.mapFromJson(json[r'questionValues']),
tos: mapValueOfType<bool>(json, r'tos'),
botId: mapValueOfType<String>(json, r'botId'),
);
}
return null;
}