fromJson static method

MmSubscription? fromJson(
  1. dynamic value
)

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

Implementation

// ignore: prefer_constructors_over_static_methods
static MmSubscription? 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(() {
      requiredKeys.forEach((key) {
        assert(json.containsKey(key), 'Required key "MmSubscription[$key]" is missing from JSON.');
        assert(json[key] != null, 'Required key "MmSubscription[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return MmSubscription(
      id: mapValueOfType<String>(json, r'id'),
      customerId: mapValueOfType<String>(json, r'customer_id'),
      productId: mapValueOfType<String>(json, r'product_id'),
      addOns: json[r'add_ons'] is List ? (json[r'add_ons'] as List).cast<String>() : const [],
      startAt: mapValueOfType<int>(json, r'start_at'),
      endAt: mapValueOfType<int>(json, r'end_at'),
      createAt: mapValueOfType<int>(json, r'create_at'),
      seats: mapValueOfType<int>(json, r'seats'),
      dns: mapValueOfType<String>(json, r'dns'),
    );
  }
  return null;
}