fromJson static method
Returns a new Subscription instance and imports its values from
value if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static Subscription? 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 "Subscription[$key]" is missing from JSON.');
assert(json[key] != null, 'Required key "Subscription[$key]" has a null value in JSON.');
});
return true;
}());
return Subscription(
cancelAtPeriodEnd: mapValueOfType<bool>(json, r'cancelAtPeriodEnd'),
canceledAt: mapValueOfType<String>(json, r'canceledAt'),
createdAt: mapValueOfType<String>(json, r'createdAt'),
currentPeriodEnd: mapValueOfType<String>(json, r'currentPeriodEnd'),
currentPeriodStart: mapValueOfType<String>(json, r'currentPeriodStart'),
defaultPaymentMethod: mapValueOfType<String>(json, r'defaultPaymentMethod'),
endedAt: mapValueOfType<String>(json, r'endedAt'),
id: mapValueOfType<String>(json, r'id'),
mrrCents: mapValueOfType<int>(json, r'mrrCents'),
plan: SubscriptionPlan.fromJson(json[r'plan']),
planId: mapValueOfType<String>(json, r'planId'),
providerType: mapValueOfType<String>(json, r'providerType'),
quantity: mapValueOfType<int>(json, r'quantity'),
status: mapValueOfType<String>(json, r'status'),
trialEnd: mapValueOfType<String>(json, r'trialEnd'),
trialStart: mapValueOfType<String>(json, r'trialStart'),
updatedAt: mapValueOfType<String>(json, r'updatedAt'),
userId: mapValueOfType<String>(json, r'userId'),
);
}
return null;
}