fromJson static method

MortgageOffer? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static MortgageOffer? 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'uuid'),
          'Required key "MortgageOffer[uuid]" is missing from JSON.');
      assert(json[r'uuid'] != null,
          'Required key "MortgageOffer[uuid]" has a null value in JSON.');
      assert(json.containsKey(r'partner'),
          'Required key "MortgageOffer[partner]" is missing from JSON.');
      assert(json[r'partner'] != null,
          'Required key "MortgageOffer[partner]" has a null value in JSON.');
      assert(json.containsKey(r'productType'),
          'Required key "MortgageOffer[productType]" is missing from JSON.');
      assert(json[r'productType'] != null,
          'Required key "MortgageOffer[productType]" has a null value in JSON.');
      assert(json.containsKey(r'productSubType'),
          'Required key "MortgageOffer[productSubType]" is missing from JSON.');
      assert(json[r'productSubType'] != null,
          'Required key "MortgageOffer[productSubType]" has a null value in JSON.');
      assert(json.containsKey(r'url'),
          'Required key "MortgageOffer[url]" is missing from JSON.');
      assert(json[r'url'] != null,
          'Required key "MortgageOffer[url]" has a null value in JSON.');
      assert(json.containsKey(r'details'),
          'Required key "MortgageOffer[details]" is missing from JSON.');
      assert(json[r'details'] != null,
          'Required key "MortgageOffer[details]" has a null value in JSON.');
      return true;
    }());

    return MortgageOffer(
      uuid: mapValueOfType<String>(json, r'uuid')!,
      partner: Partner.fromJson(json[r'partner'])!,
      marketplace: Partner.fromJson(json[r'marketplace']),
      productType: ProductType.fromJson(json[r'productType'])!,
      productSubType: ProductSubType.fromJson(json[r'productSubType'])!,
      url: mapValueOfType<String>(json, r'url')!,
      recommendationScore: num.parse('${json[r'recommendationScore']}'),
      disclaimer: mapValueOfType<String>(json, r'disclaimer'),
      productSubTypeDisclaimer:
          mapValueOfType<String>(json, r'productSubTypeDisclaimer'),
      expiresAt: mapDateTime(json, r'expiresAt', r''),
      rank: mapValueOfType<int>(json, r'rank'),
      details: MortgageOfferDetails.fromJson(json[r'details'])!,
    );
  }
  return null;
}