fromJson static method

ContentDto? fromJson(
  1. dynamic value
)

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

Implementation

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

    return ContentDto(
      stringValue: mapValueOfType<String>(json, r'stringValue'),
      numberValue: mapValueOfType<double>(json, r'numberValue'),
      booleanValue: mapValueOfType<bool>(json, r'booleanValue'),
      instantValue: mapDateTime(json, r'instantValue', ''),
      fuzzyDateValue: mapValueOfType<int>(json, r'fuzzyDateValue'),
      binaryValue: mapValueOfType<String>(json, r'binaryValue'),
      documentId: mapValueOfType<String>(json, r'documentId'),
      measureValue: MeasureDto.fromJson(json[r'measureValue']),
      medicationValue: MedicationDto.fromJson(json[r'medicationValue']),
      timeSeries: TimeSeriesDto.fromJson(json[r'timeSeries']),
      compoundValue: ServiceDto.listFromJson(json[r'compoundValue']) ?? const [],
      ratio: MeasureDto.listFromJson(json[r'ratio']) ?? const [],
      range: MeasureDto.listFromJson(json[r'range']) ?? const [],
    );
  }
  return null;
}