fromJson static method

LoanProbability? fromJson(
  1. dynamic value
)

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

Implementation

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

    return LoanProbability(
      probability: mapValueOfType<double>(json, r'probability')!,
      aprPercentMin: mapValueOfType<double>(json, r'aprPercentMin')!,
      aprPercentMax: mapValueOfType<double>(json, r'aprPercentMax')!,
      termMonthsMin: mapValueOfType<int>(json, r'termMonthsMin')!,
      termMonthsMax: mapValueOfType<int>(json, r'termMonthsMax')!,
      productSubType: ProductSubType.fromJson(json[r'productSubType']),
    );
  }
  return null;
}