FilterConverter class

Converter for Filter type.

Provides static methods for serializing and deserializing Zorphy Filter objects.

The converter works with Filter<dynamic> to avoid generic type constraints that json_serializable cannot handle directly.

Serialization

Filters are serialized using their built-in toJson() method, which is automatically generated by the Zorphy code generator.

Deserialization

Deserialization is limited and requires manual creation of Field objects. The converter can reconstruct simple comparison filters and logical operators, but complex filters may need custom handling.

For full deserialization support, consider:

  • Using a custom Field registry
  • Implementing entity-specific deserializers
  • Storing filters in a format that preserves field type information

Example

// Serialization
final filter = Filter.eq(User.name, 'John');
final json = FilterConverter.toJson(filter);
// json: {'name': 'John'}

// Deserialization (requires manual Field creation)
final userField = Field<User, String>('name', (u) => u.name);
final decoded = FilterConverter.fromJson({'name': 'John'}, userField);
// decoded: Filter.eq(userField, 'John')

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

fromJson(Map<String, dynamic>? json, [Map<String, Field>? fields, FieldResolver? resolveField]) → Filter?
Deserializes a Filter from JSON.
fromJsonTyped<T>(Map<String, dynamic>? json, [Map<String, Field<T, dynamic>>? fields, FieldResolver<T>? resolveField]) → Filter<T>?
Deserializes a typed Filter from JSON.
toJson(Filter? filter) → Map<String, dynamic>?
Serializes a Filter to JSON.
toJsonTyped<T>(Filter<T>? filter) → Map<String, dynamic>?
Serializes a typed Filter to JSON while preserving generic context for clearer error messages.