fromJson static method

ServiceDto? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static ServiceDto? fromJson(dynamic value) {
  if (value is ServiceDto) {
    return value;
  }
  if (value is Map) {
    final json = {
      "identifier": [],
      "subContactIds": {},
      "plansOfActionIds": {},
      "healthElementsIds": {},
      "formIds": {},
      "secretForeignKeys": {},
      "cryptedForeignKeys": {},
      "delegations": {},
      "encryptionKeys": {},
      "content": {},
      "textIndexes": {},
      "invoicingCodes": {},
      "notes": [],
      "qualifiedLinks": {},
      "codes": {},
      "tags": {},
      ...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 "ServiceDto[$key]" is missing from JSON.');
        assert(json[key] != null, 'Required key "ServiceDto[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return ServiceDto(
      id: mapValueOfType<String>(json, r'id')!,
      transactionId: mapValueOfType<String>(json, r'transactionId'),
      identifier: IdentifierDto.listFromJson(json[r'identifier'])!,
      contactId: mapValueOfType<String>(json, r'contactId'),
      subContactIds: json[r'subContactIds'] is Set
          ? (json[r'subContactIds'] as Set).cast<String>()
          : json[r'subContactIds'] is List
              ? ((json[r'subContactIds'] as List).toSet()).cast<String>()
              : const {},
      plansOfActionIds: json[r'plansOfActionIds'] is Set
          ? (json[r'plansOfActionIds'] as Set).cast<String>()
          : json[r'plansOfActionIds'] is List
              ? ((json[r'plansOfActionIds'] as List).toSet()).cast<String>()
              : const {},
      healthElementsIds: json[r'healthElementsIds'] is Set
          ? (json[r'healthElementsIds'] as Set).cast<String>()
          : json[r'healthElementsIds'] is List
              ? ((json[r'healthElementsIds'] as List).toSet()).cast<String>()
              : const {},
      formIds: json[r'formIds'] is Set
          ? (json[r'formIds'] as Set).cast<String>()
          : json[r'formIds'] is List
              ? ((json[r'formIds'] as List).toSet()).cast<String>()
              : const {},
      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']),
      label: mapValueOfType<String>(json, r'label'),
      index: mapValueOfType<int>(json, r'index'),
      content: json[r'content'] == null ? const {} : ContentDto.mapFromJson(json[r'content']),
      encryptedContent: mapValueOfType<String>(json, r'encryptedContent'),
      textIndexes: mapCastOfType<String, String>(json, r'textIndexes')!,
      valueDate: mapValueOfType<int>(json, r'valueDate'),
      openingDate: mapValueOfType<int>(json, r'openingDate'),
      closingDate: mapValueOfType<int>(json, r'closingDate'),
      formId: mapValueOfType<String>(json, r'formId'),
      created: mapValueOfType<int>(json, r'created'),
      modified: mapValueOfType<int>(json, r'modified'),
      endOfLife: mapValueOfType<int>(json, r'endOfLife'),
      author: mapValueOfType<String>(json, r'author'),
      responsible: mapValueOfType<String>(json, r'responsible'),
      medicalLocationId: mapValueOfType<String>(json, r'medicalLocationId'),
      comment: mapValueOfType<String>(json, r'comment'),
      status: mapValueOfType<int>(json, r'status'),
      invoicingCodes: json[r'invoicingCodes'] is Set
          ? (json[r'invoicingCodes'] as Set).cast<String>()
          : json[r'invoicingCodes'] is List
              ? ((json[r'invoicingCodes'] as List).toSet()).cast<String>()
              : const {},
      notes: AnnotationDto.listFromJson(json[r'notes'])!,
      qualifiedLinks: mapCastOfType<String, Map<String, String>>(json, r'qualifiedLinks')!,
      codes: CodeStubDto.listFromJson(json[r'codes'])!.toSet(),
      tags: CodeStubDto.listFromJson(json[r'tags'])!.toSet(),
      encryptedSelf: mapValueOfType<String>(json, r'encryptedSelf'),
    );
  }
  return null;
}