fromJson static method

CodeDto? fromJson(
  1. dynamic value
)

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

Implementation

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

    return CodeDto(
      id: mapValueOfType<String>(json, r'id')!,
      rev: mapValueOfType<String>(json, r'rev'),
      deletionDate: mapValueOfType<int>(json, r'deletionDate'),
      context: mapValueOfType<String>(json, r'context'),
      type: mapValueOfType<String>(json, r'type'),
      code: mapValueOfType<String>(json, r'code'),
      version: mapValueOfType<String>(json, r'version'),
      label: mapCastOfType<String, String>(json, r'label') ?? const {},
      author: mapValueOfType<String>(json, r'author'),
      regions: json[r'regions'] is Set
          ? (json[r'regions'] as Set).cast<String>()
          : json[r'regions'] is List
              ? ((json[r'regions'] as List).toSet()).cast<String>()
              : const {},
      periodicity: PeriodicityDto.listFromJson(json[r'periodicity'])!.toSet(),
      level: mapValueOfType<int>(json, r'level'),
      links: json[r'links'] is Set
          ? (json[r'links'] as Set).cast<String>()
          : json[r'links'] is List
              ? ((json[r'links'] as List).toSet()).cast<String>()
              : const {},
      qualifiedLinks: json[r'qualifiedLinks'] == null ? const {} : mapWithListOfStringsFromJson(json[r'qualifiedLinks']),
      flags: CodeDtoFlagsEnum.listFromJson(json[r'flags'])!.toSet(),
      searchTerms: json[r'searchTerms'] == null ? const {} : mapWithSetOfStringsFromJson(json[r'searchTerms']),
      data: mapValueOfType<String>(json, r'data'),
      appendices: mapCastOfType<String, String>(json, r'appendices')!,
      disabled: mapValueOfType<bool>(json, r'disabled')!,
    );
  }
  return null;
}