fromJson static method
Returns a new OwnUserResponse instance and imports its values from
value if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static OwnUserResponse? 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'created_at'),
'Required key "OwnUserResponse[created_at]" is missing from JSON.');
assert(json[r'created_at'] != null,
'Required key "OwnUserResponse[created_at]" has a null value in JSON.');
assert(json.containsKey(r'custom'),
'Required key "OwnUserResponse[custom]" is missing from JSON.');
assert(json[r'custom'] != null,
'Required key "OwnUserResponse[custom]" has a null value in JSON.');
assert(json.containsKey(r'devices'),
'Required key "OwnUserResponse[devices]" is missing from JSON.');
assert(json[r'devices'] != null,
'Required key "OwnUserResponse[devices]" has a null value in JSON.');
assert(json.containsKey(r'id'),
'Required key "OwnUserResponse[id]" is missing from JSON.');
assert(json[r'id'] != null,
'Required key "OwnUserResponse[id]" has a null value in JSON.');
assert(json.containsKey(r'language'),
'Required key "OwnUserResponse[language]" is missing from JSON.');
assert(json[r'language'] != null,
'Required key "OwnUserResponse[language]" has a null value in JSON.');
assert(json.containsKey(r'role'),
'Required key "OwnUserResponse[role]" is missing from JSON.');
assert(json[r'role'] != null,
'Required key "OwnUserResponse[role]" has a null value in JSON.');
assert(json.containsKey(r'teams'),
'Required key "OwnUserResponse[teams]" is missing from JSON.');
assert(json[r'teams'] != null,
'Required key "OwnUserResponse[teams]" has a null value in JSON.');
assert(json.containsKey(r'updated_at'),
'Required key "OwnUserResponse[updated_at]" is missing from JSON.');
assert(json[r'updated_at'] != null,
'Required key "OwnUserResponse[updated_at]" has a null value in JSON.');
return true;
}());
return OwnUserResponse(
avgResponseTime: mapValueOfType<int>(json, r'avg_response_time'),
blockedUserIds: json[r'blocked_user_ids'] is Iterable
? (json[r'blocked_user_ids'] as Iterable)
.cast<String>()
.toList(growable: false)
: const [],
createdAt: mapDateTime(json, r'created_at', r'')!,
custom: mapCastOfType<String, Object>(json, r'custom')!,
deactivatedAt: mapDateTime(json, r'deactivated_at', r''),
deletedAt: mapDateTime(json, r'deleted_at', r''),
devices: DeviceResponse.listFromJson(json[r'devices']),
id: mapValueOfType<String>(json, r'id')!,
image: mapValueOfType<String>(json, r'image'),
language: mapValueOfType<String>(json, r'language')!,
lastActive: mapDateTime(json, r'last_active', r''),
name: mapValueOfType<String>(json, r'name'),
privacySettings: mapValueOfType<Object>(json, r'privacy_settings'),
pushPreferences:
PushPreferencesResponse.fromJson(json[r'push_preferences']),
revokeTokensIssuedBefore:
mapDateTime(json, r'revoke_tokens_issued_before', r''),
role: mapValueOfType<String>(json, r'role')!,
teams: json[r'teams'] is Iterable
? (json[r'teams'] as Iterable)
.cast<String>()
.toList(growable: false)
: const [],
teamsRole:
mapCastOfType<String, String>(json, r'teams_role') ?? const {},
updatedAt: mapDateTime(json, r'updated_at', r'')!,
);
}
return null;
}