SimilarTo.fromJson constructor
SimilarTo.fromJson(
- Object? json_
Returns a new instance from a JSON value. May throw if the value does not have the expected structure.
Implementation
factory SimilarTo.fromJson(Object? json_) {
final json = json_ is Map
? _spec.fields.map((f) => json_[f.label]).toList(growable: false)
: json_;
return switch (json) {
[final negated, final expr, final pattern, final escapeChar] ||
(final negated, final expr, final pattern, final escapeChar) =>
SimilarTo(
negated: negated! as bool,
expr: ExprRef.fromJson(expr),
pattern: ExprRef.fromJson(pattern),
escapeChar:
Option.fromJson(escapeChar, (some) => some! as String).value,
),
_ => throw Exception('Invalid JSON $json_')
};
}