fromJson static method

ReportByHistogramBucket? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static ReportByHistogramBucket? 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(() {
      assert(json.containsKey(r'category'),
          'Required key "ReportByHistogramBucket[category]" is missing from JSON.');
      assert(json[r'category'] != null,
          'Required key "ReportByHistogramBucket[category]" has a null value in JSON.');
      assert(json.containsKey(r'count'),
          'Required key "ReportByHistogramBucket[count]" is missing from JSON.');
      assert(json[r'count'] != null,
          'Required key "ReportByHistogramBucket[count]" has a null value in JSON.');
      assert(json.containsKey(r'sum'),
          'Required key "ReportByHistogramBucket[sum]" is missing from JSON.');
      assert(json[r'sum'] != null,
          'Required key "ReportByHistogramBucket[sum]" has a null value in JSON.');
      return true;
    }());

    return ReportByHistogramBucket(
      category: mapValueOfType<String>(json, r'category')!,
      count: mapValueOfType<int>(json, r'count')!,
      lowerBound: Bound.fromJson(json[r'lower_bound']),
      sum: mapValueOfType<double>(json, r'sum')!,
      upperBound: Bound.fromJson(json[r'upper_bound']),
    );
  }
  return null;
}