fromJson static method

LoanReport? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static LoanReport? 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 "LoanReport[uuid]" is missing from JSON.');
      assert(json[r'uuid'] != null,
          'Required key "LoanReport[uuid]" has a null value in JSON.');
      assert(json.containsKey(r'annualIncome'),
          'Required key "LoanReport[annualIncome]" is missing from JSON.');
      assert(json[r'annualIncome'] != null,
          'Required key "LoanReport[annualIncome]" has a null value in JSON.');
      assert(json.containsKey(r'creditRating'),
          'Required key "LoanReport[creditRating]" is missing from JSON.');
      assert(json[r'creditRating'] != null,
          'Required key "LoanReport[creditRating]" has a null value in JSON.');
      assert(json.containsKey(r'networkProbabilities'),
          'Required key "LoanReport[networkProbabilities]" is missing from JSON.');
      assert(json[r'networkProbabilities'] != null,
          'Required key "LoanReport[networkProbabilities]" has a null value in JSON.');
      assert(json.containsKey(r'financialInsitutions'),
          'Required key "LoanReport[financialInsitutions]" is missing from JSON.');
      assert(json[r'financialInsitutions'] != null,
          'Required key "LoanReport[financialInsitutions]" has a null value in JSON.');
      assert(json.containsKey(r'createdAt'),
          'Required key "LoanReport[createdAt]" is missing from JSON.');
      assert(json[r'createdAt'] != null,
          'Required key "LoanReport[createdAt]" has a null value in JSON.');
      return true;
    }());

    return LoanReport(
      uuid: mapValueOfType<String>(json, r'uuid')!,
      annualIncome: mapValueOfType<int>(json, r'annualIncome')!,
      creditRating: ProvidedCreditRating.fromJson(json[r'creditRating'])!,
      totalDebt: mapValueOfType<int>(json, r'totalDebt'),
      countOfDerogatories: mapValueOfType<int>(json, r'countOfDerogatories'),
      state: State.fromJson(json[r'state']),
      loanPurpose: LoanPurpose.fromJson(json[r'loanPurpose']),
      loanAmount: mapValueOfType<int>(json, r'loanAmount'),
      networkProbabilities:
          LoanProbability.listFromJson(json[r'networkProbabilities']),
      financialInsitutions: FinancialInstitutionLoanReport.listFromJson(
          json[r'financialInsitutions']),
      createdAt: mapDateTime(json, r'createdAt', r'')!,
    );
  }
  return null;
}