diff --git a/angel_serialize_generator/CHANGELOG.md b/angel_serialize_generator/CHANGELOG.md index cbbecf38..c0e55564 100644 --- a/angel_serialize_generator/CHANGELOG.md +++ b/angel_serialize_generator/CHANGELOG.md @@ -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. diff --git a/angel_serialize_generator/lib/build_context.dart b/angel_serialize_generator/lib/build_context.dart index 0c8ce626..140543cf 100644 --- a/angel_serialize_generator/lib/build_context.dart +++ b/angel_serialize_generator/lib/build_context.dart @@ -42,10 +42,12 @@ Future buildContext( List 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( // 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()); diff --git a/angel_serialize_generator/test/models/author.dart b/angel_serialize_generator/test/models/author.dart index ebf99092..e88924ba 100644 --- a/angel_serialize_generator/test/models/author.dart +++ b/angel_serialize_generator/test/models/author.dart @@ -10,19 +10,19 @@ part 'author.serializer.g.dart'; @serializable abstract class _Author extends Model { - String name; - int age; - List books; - Book newestBook; + String get name; + int get age; + List 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 collection; + Map get collection; }