json_delta 0.1.0 json_delta: ^0.1.0 copied to clipboard
Dart extension for serializing and an object to a JSON delta.
Introducing a mixin class that implements a toJsonDelta()
method that serializes
the object to a JSON map of values of the changes in the object.
Usage #
final person = Person("John", "Doe", 30);
person.lastName = "Smith";
person.age = 31;
final delta = person.toJsonDelta(); // {"lastName": "Smith", "age": 31}
Implement in your models #
class Person extends JsonSerializable with JsonDelta {
String firstName;
String lastName;
int age;
Person({
required this.firstName,
required this.lastName,
required this.age,
}) {
saveJsonDeltaState();
}
@override
Map<String, dynamic> toJson() {
return {
'firstName': firstName,
'lastName': lastName,
'age': age,
};
}
}
Additional information #
This package is compatible with json_serializable
which facilitates your generation of JSON.