fromJson static method

UserDto? fromJson(
  1. dynamic value
)

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

Implementation

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

    return UserDto(
      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: PropertyStubDto.listFromJson(json[r'properties'])!.toSet(),
      permissions: PermissionDto.listFromJson(json[r'permissions'])!.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 {},
      type: UserDtoTypeEnum.fromJson(json[r'type']),
      status: UserDtoStatusEnum.fromJson(json[r'status']),
      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']),
      createdDate: mapDateTime(json, r'createdDate', ''),
      termsOfUseDate: mapDateTime(json, r'termsOfUseDate', ''),
      email: mapValueOfType<String>(json, r'email'),
      mobilePhone: mapValueOfType<String>(json, r'mobilePhone'),
      applicationTokens: mapCastOfType<String, String>(json, r'applicationTokens')!,
      authenticationTokens: mapCastOfType<String, AuthenticationTokenDto>(json, r'authenticationTokens')!,
    );
  }
  return null;
}