fromJson static method

Content? fromJson(
  1. dynamic value
)

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

Implementation

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

    return Content(
      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: Measure.fromJson(json[r'measureValue']),
      timeSeries: TimeSeries.fromJson(json[r'timeSeries']),
      compoundValue: DataSample.listFromJson(json[r'compoundValue']) ?? const [],
      ratio: Measure.listFromJson(json[r'ratio']) ?? const [],
      range: Measure.listFromJson(json[r'range']) ?? const [],
    );
  }
  return null;
}