Support generic types

This commit is contained in:
Tobe O 2018-02-27 14:50:46 -05:00
parent c0d57bf8b1
commit 1fac0bfee0
2 changed files with 14 additions and 3 deletions

View file

@ -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<Serializable> {
final bool autoSnakeCaseNames;
final bool autoIdAndDateFields;
@ -50,7 +61,7 @@ class JsonModelGenerator extends GeneratorForAnnotation<Serializable> {
b
..name = field.name
..modifier = FieldModifier.final$
..type = new Reference(field.type.name);
..type = convertTypeReference(field.type);
}));
}
}));

View file

@ -13,7 +13,7 @@ class Author {
final int age;
final List books;
final List<Book> books;
final Book newestBook;
@ -25,7 +25,7 @@ class Author {
class Library {
final String id;
final Map collection;
final Map<String, Book> collection;
final DateTime createdAt;