fromJson static method

PrefillResponse? fromJson(
  1. dynamic value
)

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

Implementation

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

    return PrefillResponse(
      productTypes: ProductType.listFromJson(json[r'productTypes']),
      prefillToken: mapValueOfType<String>(json, r'prefillToken')!,
      expiresInSeconds: num.parse('${json[r'expiresInSeconds']}'),
      maxUses: num.parse('${json[r'maxUses']}'),
      partnerPageUrl: mapValueOfType<String>(json, r'partnerPageUrl'),
      embedSnippet: mapValueOfType<String>(json, r'embedSnippet'),
    );
  }
  return null;
}