fromJson static method

ProductSearchResponse? fromJson(
  1. dynamic value
)

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

Implementation

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

    return ProductSearchResponse(
      response: ProductSearchResponseResponse.fromJson(json[r'response']),
      facetCounts: ProductSearchResponseFacetCounts.fromJson(json[r'facet_counts']),
      categoryMap: mapValueOfType<dynamic>(json, r'category_map'),
      didYouMean: mapValueOfType<dynamic>(json, r'did_you_mean'),
    );
  }
  return null;
}