fromJson static method

DeviceDto? fromJson(
  1. dynamic value
)

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

Implementation

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

    return DeviceDto(
      id: mapValueOfType<String>(json, r'id')!,
      rev: mapValueOfType<String>(json, r'rev'),
      deletionDate: mapValueOfType<int>(json, r'deletionDate'),
      identifiers: IdentifierDto.listFromJson(json[r'identifiers'])!,
      created: mapValueOfType<int>(json, r'created'),
      modified: mapValueOfType<int>(json, r'modified'),
      author: mapValueOfType<String>(json, r'author'),
      responsible: mapValueOfType<String>(json, r'responsible'),
      tags: CodeStubDto.listFromJson(json[r'tags'])!.toSet(),
      codes: CodeStubDto.listFromJson(json[r'codes'])!.toSet(),
      endOfLife: mapValueOfType<int>(json, r'endOfLife'),
      medicalLocationId: mapValueOfType<String>(json, r'medicalLocationId'),
      externalId: mapValueOfType<String>(json, r'externalId'),
      name: mapValueOfType<String>(json, r'name'),
      type: mapValueOfType<String>(json, r'type'),
      brand: mapValueOfType<String>(json, r'brand'),
      model: mapValueOfType<String>(json, r'model'),
      serialNumber: mapValueOfType<String>(json, r'serialNumber'),
      parentId: mapValueOfType<String>(json, r'parentId'),
      picture: json[r'picture'] is List ? (json[r'picture'] as List).cast<String>() : const [],
      properties: PropertyStubDto.listFromJson(json[r'properties'])!.toSet(),
      hcPartyKeys: json[r'hcPartyKeys'] == null ? const {} : mapWithListOfStringsFromJson(json[r'hcPartyKeys']),
      aesExchangeKeys: json[r'aesExchangeKeys'] == null ? const {} : mapOf(json[r'aesExchangeKeys'], (el) => mapWithMapOfStringsFromJson(el)),
      transferKeys: json[r'transferKeys'] == null ? const {} : mapWithMapOfStringsFromJson(json[r'transferKeys']),
      privateKeyShamirPartitions: mapCastOfType<String, String>(json, r'privateKeyShamirPartitions')!,
      publicKey: mapValueOfType<String>(json, r'publicKey'),
    );
  }
  return null;
}