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
|
# 2.0.5
|
||||||
* Deserialization now supports un-serialized `DateTime`.
|
* Deserialization now supports un-serialized `DateTime`.
|
||||||
* Better support for regular typed Lists and Maps in TypeScript.
|
* Better support for regular typed Lists and Maps in TypeScript.
|
||||||
|
|
|
@ -42,10 +42,12 @@ Future<BuildContext> buildContext(
|
||||||
List<String> fieldNames = [];
|
List<String> fieldNames = [];
|
||||||
|
|
||||||
for (var field in clazz.fields) {
|
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);
|
fieldNames.add(field.name);
|
||||||
// Skip if annotated with @exclude
|
// Skip if annotated with @exclude
|
||||||
var excludeAnnotation = excludeTypeChecker.firstAnnotationOf(field);
|
var excludeAnnotation = excludeTypeChecker.firstAnnotationOf(el);
|
||||||
|
|
||||||
if (excludeAnnotation != null) {
|
if (excludeAnnotation != null) {
|
||||||
var cr = new ConstantReader(excludeAnnotation);
|
var cr = new ConstantReader(excludeAnnotation);
|
||||||
|
@ -58,7 +60,7 @@ Future<BuildContext> buildContext(
|
||||||
|
|
||||||
// Check for alias
|
// Check for alias
|
||||||
Alias alias;
|
Alias alias;
|
||||||
var aliasAnn = aliasTypeChecker.firstAnnotationOf(field);
|
var aliasAnn = aliasTypeChecker.firstAnnotationOf(el);
|
||||||
|
|
||||||
if (aliasAnn != null) {
|
if (aliasAnn != null) {
|
||||||
alias = new Alias(aliasAnn.getField('name').toStringValue());
|
alias = new Alias(aliasAnn.getField('name').toStringValue());
|
||||||
|
|
|
@ -10,19 +10,19 @@ part 'author.serializer.g.dart';
|
||||||
|
|
||||||
@serializable
|
@serializable
|
||||||
abstract class _Author extends Model {
|
abstract class _Author extends Model {
|
||||||
String name;
|
String get name;
|
||||||
int age;
|
int get age;
|
||||||
List<Book> books;
|
List<Book> get books;
|
||||||
Book newestBook;
|
Book get newestBook;
|
||||||
|
|
||||||
@exclude
|
@exclude
|
||||||
String secret;
|
String get secret;
|
||||||
|
|
||||||
@Exclude(canDeserialize: true)
|
@Exclude(canDeserialize: true)
|
||||||
String obscured;
|
String get obscured;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable(serializers: Serializers.all)
|
@Serializable(serializers: Serializers.all)
|
||||||
abstract class _Library extends Model {
|
abstract class _Library extends Model {
|
||||||
Map<String, Book> collection;
|
Map<String, Book> get collection;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue