fromJson static method
Returns a new SampleReq instance and imports its values from
value if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static SampleReq? 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 "SampleReq[$key]" is missing from JSON.');
assert(json[key] != null, 'Required key "SampleReq[$key]" has a null value in JSON.');
});
return true;
}());
return SampleReq(
account: mapValueOfType<String>(json, r'account'),
cachedInputTokens: mapValueOfType<int>(json, r'cachedInputTokens'),
confidence: mapValueOfType<String>(json, r'confidence'),
costCents: mapValueOfType<int>(json, r'costCents'),
costLimitCents: mapValueOfType<int>(json, r'costLimitCents'),
currency: mapValueOfType<String>(json, r'currency'),
inputTokens: mapValueOfType<int>(json, r'inputTokens'),
kind: mapValueOfType<String>(json, r'kind'),
lane: mapValueOfType<String>(json, r'lane'),
machine: mapValueOfType<String>(json, r'machine'),
outputTokens: mapValueOfType<int>(json, r'outputTokens'),
plan: mapValueOfType<String>(json, r'plan'),
provider: mapValueOfType<String>(json, r'provider'),
requests: mapValueOfType<int>(json, r'requests'),
resetsAt: mapValueOfType<String>(json, r'resetsAt'),
synthetic: mapValueOfType<bool>(json, r'synthetic'),
totalTokens: mapValueOfType<int>(json, r'totalTokens'),
usedPct: num.parse('${json[r'usedPct']}'),
window: mapValueOfType<String>(json, r'window'),
windowMinutes: mapValueOfType<int>(json, r'windowMinutes'),
windowStart: mapValueOfType<String>(json, r'windowStart'),
);
}
return null;
}