Remove defaults

This commit is contained in:
Tobe O 2018-07-11 09:06:03 -04:00
parent c6f0ec4c71
commit 79ca9a6945
6 changed files with 26 additions and 17 deletions

View file

@ -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 # 2.0.9+1
* Fix a cast error when deserializing nested model classes. * Fix a cast error when deserializing nested model classes.

View file

@ -15,10 +15,6 @@ builders:
- ".d.ts" - ".d.ts"
required_inputs: required_inputs:
- .dart - .dart
defaults:
generate_for:
- "lib/src/models/**.dart"
- "test/**.dart"
targets: targets:
_book: _book:
sources: sources:

View file

@ -110,15 +110,17 @@ class SerializerGenerator extends GeneratorForAnnotation<Serializable> {
var t = field.type as InterfaceType; var t = field.type as InterfaceType;
if (isListModelType(t)) { if (isListModelType(t)) {
var rc = new ReCase(t.typeArguments[0].name); //var rc = new ReCase(t.typeArguments[0].name);
serializedRepresentation = 'model.${field.name}?.map(${rc serializedRepresentation = '''
.pascalCase}Serializer.toMap)?.toList()'; model.${field.name}
?.map((m) => m.toJson())
?.toList()''';
} else if (isMapToModelType(t)) { } else if (isMapToModelType(t)) {
var rc = new ReCase(t.typeArguments[1].name); var rc = new ReCase(t.typeArguments[1].name);
serializedRepresentation = serializedRepresentation =
'''model.${field.name}.keys?.fold({}, (map, key) { '''model.${field.name}.keys?.fold({}, (map, key) {
return map..[key] = ${serializerToMap( return map..[key] =
rc, 'model.${field.name}[key]')}; ${serializerToMap(rc, 'model.${field.name}[key]')};
})'''; })''';
} else if (t.element.isEnum) { } else if (t.element.isEnum) {
serializedRepresentation = ''' serializedRepresentation = '''
@ -202,7 +204,7 @@ class SerializerGenerator extends GeneratorForAnnotation<Serializable> {
else if (isModelClass(field.type)) { else if (isModelClass(field.type)) {
var rc = new ReCase(field.type.name); var rc = new ReCase(field.type.name);
deserializedRepresentation = "map['$alias'] != null" deserializedRepresentation = "map['$alias'] != null"
" ? ${rc.pascalCase}Serializer.fromMap(map['$alias'])" " ? ${rc.pascalCase}Serializer.fromMap(map['$alias'] as Map)"
" : null"; " : null";
} else if (field.type is InterfaceType) { } else if (field.type is InterfaceType) {
var t = field.type as InterfaceType; var t = field.type as InterfaceType;
@ -227,11 +229,11 @@ class SerializerGenerator extends GeneratorForAnnotation<Serializable> {
} else if (t.element.isEnum) { } else if (t.element.isEnum) {
deserializedRepresentation = ''' deserializedRepresentation = '''
map['$alias'] is ${t.name} map['$alias'] is ${t.name}
? map['$alias'] ? (map['$alias'] as ${t.name})
: :
( (
map['$alias'] is int map['$alias'] is int
? ${t.name}.values[map['$alias']] ? ${t.name}.values[map['$alias'] as int]
: null : null
) )
'''; ''';

View file

@ -1,5 +1,5 @@
name: angel_serialize_generator 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. description: Model serialization generators, designed for use with Angel. Combine with angel_serialize for flexible modeling.
author: Tobe O <thosakwe@gmail.com> author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/serialize homepage: https://github.com/angel-dart/serialize

View file

@ -26,7 +26,7 @@ abstract class AuthorSerializer {
.map(BookSerializer.fromMap)) .map(BookSerializer.fromMap))
: null, : null,
newestBook: map['newest_book'] != null newestBook: map['newest_book'] != null
? BookSerializer.fromMap(map['newest_book']) ? BookSerializer.fromMap(map['newest_book'] as Map)
: null, : null,
obscured: map['obscured'] as String, obscured: map['obscured'] as String,
createdAt: map['created_at'] != null createdAt: map['created_at'] != null
@ -57,7 +57,7 @@ abstract class AuthorSerializer {
'id': model.id, 'id': model.id,
'name': model.name, 'name': model.name,
'age': model.age, 'age': model.age,
'books': model.books?.map(BookSerializer.toMap)?.toList(), 'books': model.books?.map((m) => m.toJson())?.toList(),
'newest_book': BookSerializer.toMap(model.newestBook), 'newest_book': BookSerializer.toMap(model.newestBook),
'created_at': model.createdAt?.toIso8601String(), 'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String() 'updated_at': model.updatedAt?.toIso8601String()

View file

@ -10,8 +10,10 @@ abstract class WithEnumSerializer {
static WithEnum fromMap(Map map) { static WithEnum fromMap(Map map) {
return new WithEnum( return new WithEnum(
type: map['type'] is WithEnumType type: map['type'] is WithEnumType
? map['type'] ? (map['type'] as WithEnumType)
: (map['type'] is int ? WithEnumType.values[map['type']] : null), : (map['type'] is int
? WithEnumType.values[map['type'] as int]
: null),
finalList: map['final_list'] as List<int>); finalList: map['final_list'] as List<int>);
} }