fromJson static method
Returns a new EnrichedReaction instance and imports its values from
value
if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static EnrichedReaction? 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(() {
requiredKeys.forEach((key) {
assert(json.containsKey(key), 'Required key "EnrichedReaction[$key]" is missing from JSON.');
assert(json[key] != null, 'Required key "EnrichedReaction[$key]" has a null value in JSON.');
});
return true;
}());
return EnrichedReaction(
activityId: mapValueOfType<String>(json, r'activity_id')!,
childrenCounts: mapCastOfType<String, int>(json, r'children_counts') ?? const {},
createdAt: mapValueOfType<Object>(json, r'created_at'),
data: mapCastOfType<String, Object>(json, r'data') ?? const {},
id: mapValueOfType<String>(json, r'id'),
kind: mapValueOfType<String>(json, r'kind')!,
latestChildren: json[r'latest_children'] == null
? const {}
: EnrichedReaction.mapListFromJson(json[r'latest_children']),
ownChildren: json[r'own_children'] == null
? const {}
: EnrichedReaction.mapListFromJson(json[r'own_children']),
parent: mapValueOfType<String>(json, r'parent'),
targetFeeds: json[r'target_feeds'] is Iterable
? (json[r'target_feeds'] as Iterable).cast<String>().toList(growable: false)
: const [],
updatedAt: mapValueOfType<Object>(json, r'updated_at'),
user: Data.fromJson(json[r'user']),
userId: mapValueOfType<String>(json, r'user_id')!,
);
}
return null;
}