Support generic types
This commit is contained in:
parent
c0d57bf8b1
commit
1fac0bfee0
2 changed files with 14 additions and 3 deletions
|
@ -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);
|
||||
}));
|
||||
}
|
||||
}));
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue