fromJson static method

User? fromJson(
  1. dynamic value
)

Returns a new User instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static User? 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 "User[$key]" is missing from JSON.');
        assert(json[key] != null, 'Required key "User[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return User(
      id: mapValueOfType<String>(json, r'id'),
      rev: mapValueOfType<String>(json, r'rev'),
      deletionDate: mapValueOfType<int>(json, r'deletionDate'),
      created: mapValueOfType<int>(json, r'created'),
      name: mapValueOfType<String>(json, r'name'),
      properties: Property.listFromJson(json[r'properties'])!.toSet(),
      roles: json[r'roles'] is Set
          ? (json[r'roles'] as Set).cast<String>()
          : json[r'roles'] is List
              ? ((json[r'roles'] as List).toSet()).cast<String>()
              : const {},
      login: mapValueOfType<String>(json, r'login'),
      passwordHash: mapValueOfType<String>(json, r'passwordHash'),
      secret: mapValueOfType<String>(json, r'secret'),
      use2fa: mapValueOfType<bool>(json, r'use2fa'),
      groupId: mapValueOfType<String>(json, r'groupId'),
      healthcarePartyId: mapValueOfType<String>(json, r'healthcarePartyId'),
      patientId: mapValueOfType<String>(json, r'patientId'),
      deviceId: mapValueOfType<String>(json, r'deviceId'),
      autoDelegations: json[r'autoDelegations'] == null ? const {} : mapWithSetOfStringsFromJson(json[r'autoDelegations']),
      email: mapValueOfType<String>(json, r'email'),
      mobilePhone: mapValueOfType<String>(json, r'mobilePhone'),
      authenticationTokens: mapValueOfType<Map<String, AuthenticationToken>>(json, r'authenticationTokens')!,
      status: mapValueOfType<UserStatus>(json, r'status'),
    );
  }
  return null;
}