fromJson static method

MaintenanceTaskDto? fromJson(
  1. dynamic value
)

Returns a new MaintenanceTaskDto instance and imports its values from json if it's non-null, null if json is null.

Implementation

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

    return MaintenanceTaskDto(
      id: json[r'id'],
      rev: json[r'rev'],
      identifier: IdentifierDto.listFromJson(json[r'identifier']) ?? const [],
      created: json[r'created'],
      modified: json[r'modified'],
      author: json[r'author'],
      responsible: json[r'responsible'],
      medicalLocationId: json[r'medicalLocationId'],
      tags: CodeStubDto.listFromJson(json[r'tags'])?.toSet() ?? const {},
      codes: CodeStubDto.listFromJson(json[r'codes'])?.toSet() ?? const {},
      endOfLife: json[r'endOfLife'],
      deletionDate: json[r'deletionDate'],
      taskType: json[r'taskType'],
      properties: PropertyStubDto.listFromJson(json[r'properties'])?.toSet() ?? const {},
      status: MaintenanceTaskDtoStatusEnum.fromJson(json[r'status'])!,
      secretForeignKeys: json[r'secretForeignKeys'] is Set
          ? (json[r'secretForeignKeys'] as Set).cast<String>()
          : json[r'secretForeignKeys'] is List
          ? ((json[r'secretForeignKeys'] as List).toSet()).cast<String>()
          : const {},
      cryptedForeignKeys: json[r'cryptedForeignKeys'] == null ? const {} : DelegationDto.mapListFromJson(json[r'cryptedForeignKeys']),
      delegations: json[r'delegations'] == null ? const {} : DelegationDto.mapListFromJson(json[r'delegations']),
      encryptionKeys: json[r'encryptionKeys'] == null ? const {} : DelegationDto.mapListFromJson(json[r'encryptionKeys']),
      encryptedSelf: mapValueOfType<String>(json, r'encryptedSelf'),
    );
  }
  return null;
}