fromJson static method
Returns a new CaptureEvent instance and imports its values from
value if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static CaptureEvent? 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 "CaptureEvent[$key]" is missing from JSON.');
assert(json[key] != null, 'Required key "CaptureEvent[$key]" has a null value in JSON.');
});
return true;
}());
return CaptureEvent(
anonymousId: mapValueOfType<String>(json, r'anonymousId'),
channel: mapValueOfType<String>(json, r'channel'),
clip: ClipBody.fromJson(json[r'clip']),
currency: mapValueOfType<String>(json, r'currency'),
distinctId: mapValueOfType<String>(json, r'distinctId'),
environment: mapValueOfType<String>(json, r'environment'),
error: ErrorBody.fromJson(json[r'error']),
event: mapValueOfType<String>(json, r'event'),
groupId: mapValueOfType<String>(json, r'groupId'),
groupType: mapValueOfType<String>(json, r'groupType'),
kind: mapValueOfType<String>(json, r'kind'),
level: mapValueOfType<String>(json, r'level'),
library_: mapValueOfType<String>(json, r'library'),
libraryVersion: mapValueOfType<String>(json, r'libraryVersion'),
log: LogBody.fromJson(json[r'log']),
messageId: mapValueOfType<String>(json, r'messageId'),
metric: MetricBody.fromJson(json[r'metric']),
path: mapValueOfType<String>(json, r'path'),
personId: mapValueOfType<String>(json, r'personId'),
product: mapValueOfType<String>(json, r'product'),
productId: mapValueOfType<String>(json, r'productId'),
properties: mapCastOfType<String, Object>(json, r'properties') ?? const {},
quantity: mapValueOfType<int>(json, r'quantity'),
refCode: mapValueOfType<String>(json, r'refCode'),
referrer: mapValueOfType<String>(json, r'referrer'),
release: mapValueOfType<String>(json, r'release'),
resource: mapValueOfType<String>(json, r'resource'),
revenue: num.parse('${json[r'revenue']}'),
service: mapValueOfType<String>(json, r'service'),
sessionId: mapValueOfType<String>(json, r'sessionId'),
signupWeek: mapValueOfType<String>(json, r'signupWeek'),
site: mapValueOfType<String>(json, r'site'),
span: SpanBody.fromJson(json[r'span']),
spanId: mapValueOfType<String>(json, r'spanId'),
timestamp: mapValueOfType<String>(json, r'timestamp'),
traceId: mapValueOfType<String>(json, r'traceId'),
type: mapValueOfType<String>(json, r'type'),
url: mapValueOfType<String>(json, r'url'),
utm: UTM.fromJson(json[r'utm']),
);
}
return null;
}