Use abstract for immutable models
This commit is contained in:
parent
1ab858d658
commit
d1da61ba64
3 changed files with 15 additions and 10 deletions
|
@ -1,3 +1,6 @@
|
|||
# 2.0.6
|
||||
* Support for using `abstract` to create immutable model classes.
|
||||
|
||||
# 2.0.5
|
||||
* Deserialization now supports un-serialized `DateTime`.
|
||||
* Better support for regular typed Lists and Maps in TypeScript.
|
||||
|
|
|
@ -42,10 +42,12 @@ Future<BuildContext> buildContext(
|
|||
List<String> fieldNames = [];
|
||||
|
||||
for (var field in clazz.fields) {
|
||||
if (field.getter != null && field.setter != null) {
|
||||
if (field.getter != null &&
|
||||
(field.setter != null || field.getter.isAbstract)) {
|
||||
var el = field.setter == null ? field.getter : field;
|
||||
fieldNames.add(field.name);
|
||||
// Skip if annotated with @exclude
|
||||
var excludeAnnotation = excludeTypeChecker.firstAnnotationOf(field);
|
||||
var excludeAnnotation = excludeTypeChecker.firstAnnotationOf(el);
|
||||
|
||||
if (excludeAnnotation != null) {
|
||||
var cr = new ConstantReader(excludeAnnotation);
|
||||
|
@ -58,7 +60,7 @@ Future<BuildContext> buildContext(
|
|||
|
||||
// Check for alias
|
||||
Alias alias;
|
||||
var aliasAnn = aliasTypeChecker.firstAnnotationOf(field);
|
||||
var aliasAnn = aliasTypeChecker.firstAnnotationOf(el);
|
||||
|
||||
if (aliasAnn != null) {
|
||||
alias = new Alias(aliasAnn.getField('name').toStringValue());
|
||||
|
|
|
@ -10,19 +10,19 @@ part 'author.serializer.g.dart';
|
|||
|
||||
@serializable
|
||||
abstract class _Author extends Model {
|
||||
String name;
|
||||
int age;
|
||||
List<Book> books;
|
||||
Book newestBook;
|
||||
String get name;
|
||||
int get age;
|
||||
List<Book> get books;
|
||||
Book get newestBook;
|
||||
|
||||
@exclude
|
||||
String secret;
|
||||
String get secret;
|
||||
|
||||
@Exclude(canDeserialize: true)
|
||||
String obscured;
|
||||
String get obscured;
|
||||
}
|
||||
|
||||
@Serializable(serializers: Serializers.all)
|
||||
abstract class _Library extends Model {
|
||||
Map<String, Book> collection;
|
||||
Map<String, Book> get collection;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue