Angel3 Serialization
The frontend for Angel3 model serialization. See Documentation
Installation
In your pubspec.yaml:
dependencies:
angel3_serialize: ^10.0.0
dev_dependencies:
angel3_serialize_generator: ^10.0.0
build_runner: ^2.4.0
Usage
Annotate a model, whose name ends with Entity, in todo.dart:
import 'package:angel3_serialize/angel3_serialize.dart';
part 'todo.g.dart';
@serializable
abstract class TodoEntity {
String? get text;
bool? get completed;
}
Run dart run build_runner build. It generates Todo, with copyWith, == and toJson, and TodoSerializer:
var todo = TodoSerializer.fromMap({'text': 'Clean your room', 'completed': false});
print(todo.toJson());
Migrating from 9.x to 10.0.0
The breaking changes of each release are listed in the CHANGELOG. Those of 10.0.0 that may need changes in an app:
-
Serializersis anenum, andSerializable.serializersaList<Serializers>. Replace integer values with the enum's:0isSerializers.map,1isSerializers.jsonand2isSerializers.typescript.// 9.x @Serializable(serializers: [0, 1]) // 10.0.0 @Serializable(serializers: [Serializers.map, Serializers.json]) -
Serializable.includeAnnotationsis aList<Object>. -
hashObjectsis no longer exported, norquivera dependency. Regenerate your models, which useObject.hashAll, and useObject.hashAllin your own code.