diff --git a/angel_serialize_generator/lib/angel_serialize_generator.dart b/angel_serialize_generator/lib/angel_serialize_generator.dart index f06d6ec7..e00a0fe2 100644 --- a/angel_serialize_generator/lib/angel_serialize_generator.dart +++ b/angel_serialize_generator/lib/angel_serialize_generator.dart @@ -12,6 +12,17 @@ import 'context.dart'; part 'model.dart'; +/// Converts a [DartType] to a [TypeReference]. +TypeReference convertTypeReference(DartType t) { + return new TypeReference((b) { + b..symbol = t.name; + + if (t is InterfaceType) { + b.types.addAll(t.typeArguments.map(convertTypeReference)); + } + }); +} + class JsonModelGenerator extends GeneratorForAnnotation { final bool autoSnakeCaseNames; final bool autoIdAndDateFields; @@ -50,7 +61,7 @@ class JsonModelGenerator extends GeneratorForAnnotation { b ..name = field.name ..modifier = FieldModifier.final$ - ..type = new Reference(field.type.name); + ..type = convertTypeReference(field.type); })); } })); diff --git a/angel_serialize_generator/test/models/author.g.dart b/angel_serialize_generator/test/models/author.g.dart index b9ec7010..c13ec86f 100644 --- a/angel_serialize_generator/test/models/author.g.dart +++ b/angel_serialize_generator/test/models/author.g.dart @@ -13,7 +13,7 @@ class Author { final int age; - final List books; + final List books; final Book newestBook; @@ -25,7 +25,7 @@ class Author { class Library { final String id; - final Map collection; + final Map collection; final DateTime createdAt;