fromJson static method
Returns a new UserBadge instance and imports its values from
value if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static UserBadge? 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 "UserBadge[_id]" is missing from JSON.');
assert(json[r'_id'] != null, 'Required key "UserBadge[_id]" has a null value in JSON.');
assert(json.containsKey(r'userId'), 'Required key "UserBadge[userId]" is missing from JSON.');
assert(json[r'userId'] != null, 'Required key "UserBadge[userId]" has a null value in JSON.');
assert(json.containsKey(r'badgeId'), 'Required key "UserBadge[badgeId]" is missing from JSON.');
assert(json[r'badgeId'] != null, 'Required key "UserBadge[badgeId]" has a null value in JSON.');
assert(json.containsKey(r'fromTenantId'), 'Required key "UserBadge[fromTenantId]" is missing from JSON.');
assert(json[r'fromTenantId'] != null, 'Required key "UserBadge[fromTenantId]" has a null value in JSON.');
assert(json.containsKey(r'createdAt'), 'Required key "UserBadge[createdAt]" is missing from JSON.');
assert(json[r'createdAt'] != null, 'Required key "UserBadge[createdAt]" has a null value in JSON.');
assert(json.containsKey(r'type'), 'Required key "UserBadge[type]" is missing from JSON.');
assert(json[r'type'] != null, 'Required key "UserBadge[type]" has a null value in JSON.');
assert(json.containsKey(r'threshold'), 'Required key "UserBadge[threshold]" is missing from JSON.');
assert(json[r'threshold'] != null, 'Required key "UserBadge[threshold]" has a null value in JSON.');
assert(json.containsKey(r'description'), 'Required key "UserBadge[description]" is missing from JSON.');
assert(json[r'description'] != null, 'Required key "UserBadge[description]" has a null value in JSON.');
assert(json.containsKey(r'displayLabel'), 'Required key "UserBadge[displayLabel]" is missing from JSON.');
assert(json[r'displayLabel'] != null, 'Required key "UserBadge[displayLabel]" has a null value in JSON.');
assert(json.containsKey(r'veteranUserThresholdMillis'), 'Required key "UserBadge[veteranUserThresholdMillis]" is missing from JSON.');
assert(json[r'veteranUserThresholdMillis'] != null, 'Required key "UserBadge[veteranUserThresholdMillis]" has a null value in JSON.');
assert(json.containsKey(r'displayedOnComments'), 'Required key "UserBadge[displayedOnComments]" is missing from JSON.');
assert(json[r'displayedOnComments'] != null, 'Required key "UserBadge[displayedOnComments]" has a null value in JSON.');
assert(json.containsKey(r'receivedAt'), 'Required key "UserBadge[receivedAt]" is missing from JSON.');
assert(json[r'receivedAt'] != null, 'Required key "UserBadge[receivedAt]" has a null value in JSON.');
return true;
}());
return UserBadge(
id: mapValueOfType<String>(json, r'_id')!,
userId: mapValueOfType<String>(json, r'userId')!,
badgeId: mapValueOfType<String>(json, r'badgeId')!,
fromTenantId: mapValueOfType<String>(json, r'fromTenantId')!,
createdAt: mapDateTime(json, r'createdAt', r'')!,
type: mapValueOfType<int>(json, r'type')!,
threshold: mapValueOfType<int>(json, r'threshold')!,
description: mapValueOfType<String>(json, r'description')!,
displayLabel: mapValueOfType<String>(json, r'displayLabel')!,
displaySrc: mapValueOfType<String>(json, r'displaySrc'),
backgroundColor: mapValueOfType<String>(json, r'backgroundColor'),
borderColor: mapValueOfType<String>(json, r'borderColor'),
textColor: mapValueOfType<String>(json, r'textColor'),
cssClass: mapValueOfType<String>(json, r'cssClass'),
veteranUserThresholdMillis: mapValueOfType<int>(json, r'veteranUserThresholdMillis')!,
displayedOnComments: mapValueOfType<bool>(json, r'displayedOnComments')!,
receivedAt: mapDateTime(json, r'receivedAt', r'')!,
order: mapValueOfType<int>(json, r'order'),
urlId: mapValueOfType<String>(json, r'urlId'),
);
}
return null;
}