Contract for objects that can be serialized to/from JSON.
Implementations must provide both instance serialization and static deserialization capabilities. The static factory pattern is preferred over constructors for better error handling and type safety.
Example implementation:
class User implements DocumentSerializable {
const User({required this.id, required this.name});
final int id;
final String name;
@override
Map<String, dynamic> toJson() => {'id': id, 'name': name};
static User fromJson(Map<String, dynamic> json) {
return User(
id: json['id'] as int,
name: json['name'] as String,
);
}
}
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
-
toJson(
) → Map< String, dynamic> - Serializes this object to a JSON-compatible map.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited