fromJson static method
Offer?
fromJson(
- dynamic value
)
Returns a new Offer instance and imports its values from
value if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static Offer? 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 "Offer[uuid]" is missing from JSON.');
assert(json[r'uuid'] != null,
'Required key "Offer[uuid]" has a null value in JSON.');
assert(json.containsKey(r'partner'),
'Required key "Offer[partner]" is missing from JSON.');
assert(json[r'partner'] != null,
'Required key "Offer[partner]" has a null value in JSON.');
assert(json.containsKey(r'productType'),
'Required key "Offer[productType]" is missing from JSON.');
assert(json[r'productType'] != null,
'Required key "Offer[productType]" has a null value in JSON.');
assert(json.containsKey(r'productSubType'),
'Required key "Offer[productSubType]" is missing from JSON.');
assert(json[r'productSubType'] != null,
'Required key "Offer[productSubType]" has a null value in JSON.');
assert(json.containsKey(r'url'),
'Required key "Offer[url]" is missing from JSON.');
assert(json[r'url'] != null,
'Required key "Offer[url]" has a null value in JSON.');
return true;
}());
return Offer(
uuid: mapValueOfType<String>(json, r'uuid')!,
partner: Partner.fromJson(json[r'partner'])!,
marketplace: Partner.fromJson(json[r'marketplace']),
productType: ProductType.fromJson(json[r'productType'])!,
productSubType: ProductSubType.fromJson(json[r'productSubType'])!,
url: mapValueOfType<String>(json, r'url')!,
recommendationScore: num.parse('${json[r'recommendationScore']}'),
disclaimer: mapValueOfType<String>(json, r'disclaimer'),
productSubTypeDisclaimer:
mapValueOfType<String>(json, r'productSubTypeDisclaimer'),
expiresAt: mapDateTime(json, r'expiresAt', r''),
rank: mapValueOfType<int>(json, r'rank'),
);
}
return null;
}