EventPathItem.fromJson constructor
EventPathItem.fromJson(
- Object? json_
Returns a new instance from a JSON value. May throw if the value does not have the expected structure.
Implementation
factory EventPathItem.fromJson(Object? json_) {
Object? json = json_;
if (json is Map) {
final rt = json['runtimeType'];
if (rt is String) {
json = (
const ['EventPathItemString', 'EventPathItemIntU32'].indexOf(rt),
json
);
} else {
final MapEntry(:key, :value) = json.entries.first;
json = (key is int ? key : int.parse(key! as String), value);
}
}
return switch (json) {
(0, final value) || [0, final value] => EventPathItemString(
value is String ? value : (value! as ParsedString).value),
(1, final value) ||
[1, final value] =>
EventPathItemIntU32(value! as int),
_ => throw Exception('Invalid JSON $json_'),
};
}