diff --git a/angel_serialize_generator/lib/angel_serialize_generator.dart b/angel_serialize_generator/lib/angel_serialize_generator.dart index 2c42d9c3..11d26be0 100644 --- a/angel_serialize_generator/lib/angel_serialize_generator.dart +++ b/angel_serialize_generator/lib/angel_serialize_generator.dart @@ -6,6 +6,7 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:angel_serialize/angel_serialize.dart'; import 'package:build/build.dart'; import 'package:code_builder/code_builder.dart'; +import 'package:recase/recase.dart'; import 'package:source_gen/source_gen.dart' hide LibraryBuilder; import 'build_context.dart'; import 'context.dart'; @@ -24,6 +25,8 @@ TypeReference convertTypeReference(DartType t) { } bool isModelClass(DartType t) { + if (t == null) return false; + if (serializableTypeChecker.hasAnnotationOf(t.element)) return true; diff --git a/angel_serialize_generator/lib/serialize.dart b/angel_serialize_generator/lib/serialize.dart index fa4b4695..781cc051 100644 --- a/angel_serialize_generator/lib/serialize.dart +++ b/angel_serialize_generator/lib/serialize.dart @@ -78,7 +78,8 @@ class SerializerGenerator extends GeneratorForAnnotation { // Serialize model classes via `XSerializer.toMap` else if (isModelClass(field.type)) { - + var rc = new ReCase(field.type.name); + serializedRepresentation = '${rc.pascalCase}Serializer.toMap(${field.name})'; } buf.write("'$alias': $serializedRepresentation"); diff --git a/angel_serialize_generator/test/models/author.serializer.g.dart b/angel_serialize_generator/test/models/author.serializer.g.dart index 7a4945ae..2a3ebcf0 100644 --- a/angel_serialize_generator/test/models/author.serializer.g.dart +++ b/angel_serialize_generator/test/models/author.serializer.g.dart @@ -13,7 +13,7 @@ abstract class AuthorSerializer { 'name': name, 'age': age, 'books': books, - 'newest_book': newestBook, + 'newest_book': BookSerializer.toMap(newestBook), 'created_at': createdAt.toIso8601String(), 'updated_at': updatedAt.toIso8601String() };