fromJson static method
Returns a new FeedPost instance and imports its values from
value if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static FeedPost? 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 "FeedPost[_id]" is missing from JSON.');
assert(json[r'_id'] != null, 'Required key "FeedPost[_id]" has a null value in JSON.');
assert(json.containsKey(r'tenantId'), 'Required key "FeedPost[tenantId]" is missing from JSON.');
assert(json[r'tenantId'] != null, 'Required key "FeedPost[tenantId]" has a null value in JSON.');
assert(json.containsKey(r'createdAt'), 'Required key "FeedPost[createdAt]" is missing from JSON.');
assert(json[r'createdAt'] != null, 'Required key "FeedPost[createdAt]" has a null value in JSON.');
return true;
}());
return FeedPost(
id: mapValueOfType<String>(json, r'_id')!,
tenantId: mapValueOfType<String>(json, r'tenantId')!,
title: mapValueOfType<String>(json, r'title'),
fromUserId: mapValueOfType<String>(json, r'fromUserId'),
fromUserDisplayName: mapValueOfType<String>(json, r'fromUserDisplayName'),
fromUserAvatar: mapValueOfType<String>(json, r'fromUserAvatar'),
fromIpHash: mapValueOfType<String>(json, r'fromIpHash'),
tags: json[r'tags'] is Iterable
? (json[r'tags'] as Iterable).cast<String>().toList(growable: false)
: const [],
weight: mapValueOfType<double>(json, r'weight'),
meta: mapCastOfType<String, String>(json, r'meta') ?? const {},
contentHTML: mapValueOfType<String>(json, r'contentHTML'),
media: FeedPostMediaItem.listFromJson(json[r'media']),
links: FeedPostLink.listFromJson(json[r'links']),
createdAt: mapDateTime(json, r'createdAt', r'')!,
reacts: mapCastOfType<String, int>(json, r'reacts') ?? const {},
commentCount: mapValueOfType<int>(json, r'commentCount'),
);
}
return null;
}