fromJson static method

EsimUsageReading? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static EsimUsageReading? 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'iccid'), 'Required key "EsimUsageReading[iccid]" is missing from JSON.');
      assert(json[r'iccid'] != null, 'Required key "EsimUsageReading[iccid]" has a null value in JSON.');
      assert(json.containsKey(r'status'), 'Required key "EsimUsageReading[status]" is missing from JSON.');
      assert(json[r'status'] != null, 'Required key "EsimUsageReading[status]" has a null value in JSON.');
      assert(json.containsKey(r'capturedAt'), 'Required key "EsimUsageReading[capturedAt]" is missing from JSON.');
      assert(json[r'capturedAt'] != null, 'Required key "EsimUsageReading[capturedAt]" has a null value in JSON.');
      assert(json.containsKey(r'isUnlimited'), 'Required key "EsimUsageReading[isUnlimited]" is missing from JSON.');
      assert(json[r'isUnlimited'] != null, 'Required key "EsimUsageReading[isUnlimited]" has a null value in JSON.');
      assert(json.containsKey(r'usageBand'), 'Required key "EsimUsageReading[usageBand]" is missing from JSON.');
      assert(json[r'usageBand'] != null, 'Required key "EsimUsageReading[usageBand]" has a null value in JSON.');
      assert(json.containsKey(r'expiryBand'), 'Required key "EsimUsageReading[expiryBand]" is missing from JSON.');
      assert(json[r'expiryBand'] != null, 'Required key "EsimUsageReading[expiryBand]" has a null value in JSON.');
      assert(json.containsKey(r'allowedData'), 'Required key "EsimUsageReading[allowedData]" is missing from JSON.');
      assert(json[r'allowedData'] != null, 'Required key "EsimUsageReading[allowedData]" has a null value in JSON.');
      assert(json.containsKey(r'remainingData'), 'Required key "EsimUsageReading[remainingData]" is missing from JSON.');
      assert(json[r'remainingData'] != null, 'Required key "EsimUsageReading[remainingData]" has a null value in JSON.');
      assert(json.containsKey(r'allowedSms'), 'Required key "EsimUsageReading[allowedSms]" is missing from JSON.');
      assert(json[r'allowedSms'] != null, 'Required key "EsimUsageReading[allowedSms]" has a null value in JSON.');
      assert(json.containsKey(r'remainingSms'), 'Required key "EsimUsageReading[remainingSms]" is missing from JSON.');
      assert(json[r'remainingSms'] != null, 'Required key "EsimUsageReading[remainingSms]" has a null value in JSON.');
      assert(json.containsKey(r'allowedVoice'), 'Required key "EsimUsageReading[allowedVoice]" is missing from JSON.');
      assert(json[r'allowedVoice'] != null, 'Required key "EsimUsageReading[allowedVoice]" has a null value in JSON.');
      assert(json.containsKey(r'remainingVoice'), 'Required key "EsimUsageReading[remainingVoice]" is missing from JSON.');
      assert(json[r'remainingVoice'] != null, 'Required key "EsimUsageReading[remainingVoice]" has a null value in JSON.');
      return true;
    }());

    return EsimUsageReading(
      iccid: mapValueOfType<String>(json, r'iccid')!,
      status: EsimUsageReadingStatusEnum.fromJson(json[r'status'])!,
      capturedAt: mapDateTime(json, r'capturedAt', r'')!,
      start: mapDateTime(json, r'start', r''),
      end: mapDateTime(json, r'end', r''),
      isUnlimited: mapValueOfType<bool>(json, r'isUnlimited')!,
      usageBand: EsimUsageReadingUsageBandEnum.fromJson(json[r'usageBand'])!,
      expiryBand: EsimUsageReadingExpiryBandEnum.fromJson(json[r'expiryBand'])!,
      allowedData: mapValueOfType<int>(json, r'allowedData')!,
      remainingData: mapValueOfType<int>(json, r'remainingData')!,
      allowedSms: mapValueOfType<int>(json, r'allowedSms')!,
      remainingSms: mapValueOfType<int>(json, r'remainingSms')!,
      allowedVoice: mapValueOfType<int>(json, r'allowedVoice')!,
      remainingVoice: mapValueOfType<int>(json, r'remainingVoice')!,
    );
  }
  return null;
}