JsonSerializable mixin
A mixin that defines the contract for JSON serialization and deserialization.
JsonSerializable provides the interface that all JSON-serializable classes must implement. It's used by JsonModel and ensures consistent serialization behavior across the codebase.
Key Methods:
Usage: Classes that need JSON serialization should mix in this mixin and implement both methods. JsonModel already includes this mixin, so models extending JsonModel automatically implement this interface.
Example:
class MyModel with JsonSerializable {
@override
void fromJson(dynamic json) {
// Deserialization logic
}
@override
dynamic toJson() {
// Serialization logic
return {};
}
}
See also:
- JsonModel for the base model class that uses this mixin
- Mixin applications
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
-
fromJson(
dynamic json) → void - Deserializes JSON data into this object instance.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toJson(
) → dynamic - Serializes this object instance to JSON format.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited