From 79ca9a6945eb0ab9dbe8c7420f484ae99fccc63d Mon Sep 17 00:00:00 2001 From: Tobe O Date: Wed, 11 Jul 2018 09:06:03 -0400 Subject: [PATCH] Remove defaults --- angel_serialize_generator/CHANGELOG.md | 9 +++++++++ angel_serialize_generator/build.yaml | 4 ---- angel_serialize_generator/lib/serialize.dart | 18 ++++++++++-------- angel_serialize_generator/pubspec.yaml | 2 +- .../test/models/author.serializer.g.dart | 4 ++-- .../test/models/with_enum.serializer.g.dart | 6 ++++-- 6 files changed, 26 insertions(+), 17 deletions(-) diff --git a/angel_serialize_generator/CHANGELOG.md b/angel_serialize_generator/CHANGELOG.md index 51e9137e..cc6af2a9 100644 --- a/angel_serialize_generator/CHANGELOG.md +++ b/angel_serialize_generator/CHANGELOG.md @@ -1,3 +1,12 @@ +# 2.0.9+4 +* Remove `defaults` in `build.yaml`. + +# 2.0.9+3 +* Fix a cast error when self-referencing nested list expressions. + +# 2.0.9+2 +* Fix previously unseen cast errors with enums. + # 2.0.9+1 * Fix a cast error when deserializing nested model classes. diff --git a/angel_serialize_generator/build.yaml b/angel_serialize_generator/build.yaml index 85a0a683..7980a8b9 100644 --- a/angel_serialize_generator/build.yaml +++ b/angel_serialize_generator/build.yaml @@ -15,10 +15,6 @@ builders: - ".d.ts" required_inputs: - .dart - defaults: - generate_for: - - "lib/src/models/**.dart" - - "test/**.dart" targets: _book: sources: diff --git a/angel_serialize_generator/lib/serialize.dart b/angel_serialize_generator/lib/serialize.dart index f1883f6a..de5ca713 100644 --- a/angel_serialize_generator/lib/serialize.dart +++ b/angel_serialize_generator/lib/serialize.dart @@ -110,15 +110,17 @@ class SerializerGenerator extends GeneratorForAnnotation { var t = field.type as InterfaceType; if (isListModelType(t)) { - var rc = new ReCase(t.typeArguments[0].name); - serializedRepresentation = 'model.${field.name}?.map(${rc - .pascalCase}Serializer.toMap)?.toList()'; + //var rc = new ReCase(t.typeArguments[0].name); + serializedRepresentation = ''' + model.${field.name} + ?.map((m) => m.toJson()) + ?.toList()'''; } else if (isMapToModelType(t)) { var rc = new ReCase(t.typeArguments[1].name); serializedRepresentation = '''model.${field.name}.keys?.fold({}, (map, key) { - return map..[key] = ${serializerToMap( - rc, 'model.${field.name}[key]')}; + return map..[key] = + ${serializerToMap(rc, 'model.${field.name}[key]')}; })'''; } else if (t.element.isEnum) { serializedRepresentation = ''' @@ -202,7 +204,7 @@ class SerializerGenerator extends GeneratorForAnnotation { else if (isModelClass(field.type)) { var rc = new ReCase(field.type.name); deserializedRepresentation = "map['$alias'] != null" - " ? ${rc.pascalCase}Serializer.fromMap(map['$alias'])" + " ? ${rc.pascalCase}Serializer.fromMap(map['$alias'] as Map)" " : null"; } else if (field.type is InterfaceType) { var t = field.type as InterfaceType; @@ -227,11 +229,11 @@ class SerializerGenerator extends GeneratorForAnnotation { } else if (t.element.isEnum) { deserializedRepresentation = ''' map['$alias'] is ${t.name} - ? map['$alias'] + ? (map['$alias'] as ${t.name}) : ( map['$alias'] is int - ? ${t.name}.values[map['$alias']] + ? ${t.name}.values[map['$alias'] as int] : null ) '''; diff --git a/angel_serialize_generator/pubspec.yaml b/angel_serialize_generator/pubspec.yaml index 703154fb..94fc4532 100644 --- a/angel_serialize_generator/pubspec.yaml +++ b/angel_serialize_generator/pubspec.yaml @@ -1,5 +1,5 @@ name: angel_serialize_generator -version: 2.0.9+1 +version: 2.0.9+3 description: Model serialization generators, designed for use with Angel. Combine with angel_serialize for flexible modeling. author: Tobe O homepage: https://github.com/angel-dart/serialize diff --git a/angel_serialize_generator/test/models/author.serializer.g.dart b/angel_serialize_generator/test/models/author.serializer.g.dart index 3d77a184..a39b3125 100644 --- a/angel_serialize_generator/test/models/author.serializer.g.dart +++ b/angel_serialize_generator/test/models/author.serializer.g.dart @@ -26,7 +26,7 @@ abstract class AuthorSerializer { .map(BookSerializer.fromMap)) : null, newestBook: map['newest_book'] != null - ? BookSerializer.fromMap(map['newest_book']) + ? BookSerializer.fromMap(map['newest_book'] as Map) : null, obscured: map['obscured'] as String, createdAt: map['created_at'] != null @@ -57,7 +57,7 @@ abstract class AuthorSerializer { 'id': model.id, 'name': model.name, 'age': model.age, - 'books': model.books?.map(BookSerializer.toMap)?.toList(), + 'books': model.books?.map((m) => m.toJson())?.toList(), 'newest_book': BookSerializer.toMap(model.newestBook), 'created_at': model.createdAt?.toIso8601String(), 'updated_at': model.updatedAt?.toIso8601String() diff --git a/angel_serialize_generator/test/models/with_enum.serializer.g.dart b/angel_serialize_generator/test/models/with_enum.serializer.g.dart index fb908a19..d7d230d2 100644 --- a/angel_serialize_generator/test/models/with_enum.serializer.g.dart +++ b/angel_serialize_generator/test/models/with_enum.serializer.g.dart @@ -10,8 +10,10 @@ abstract class WithEnumSerializer { static WithEnum fromMap(Map map) { return new WithEnum( type: map['type'] is WithEnumType - ? map['type'] - : (map['type'] is int ? WithEnumType.values[map['type']] : null), + ? (map['type'] as WithEnumType) + : (map['type'] is int + ? WithEnumType.values[map['type'] as int] + : null), finalList: map['final_list'] as List); }