Detect model class

This commit is contained in:
Tobe O 2018-02-27 20:18:48 -05:00
parent acce9a4bb8
commit 236ef55230
2 changed files with 17 additions and 0 deletions

View file

@ -21,4 +21,15 @@ TypeReference convertTypeReference(DartType t) {
b.types.addAll(t.typeArguments.map(convertTypeReference));
}
});
}
bool isModelClass(DartType t) {
if (serializableTypeChecker.hasAnnotationOf(t.element))
return true;
if (t is InterfaceType) {
return isModelClass(t.superclass);
} else {
return false;
}
}

View file

@ -72,9 +72,15 @@ class SerializerGenerator extends GeneratorForAnnotation<Serializable> {
String serializedRepresentation = field.name;
// Serialize dates
if (dateTimeTypeChecker.isAssignableFromType(field.type))
serializedRepresentation = '${field.name}.toIso8601String()';
// Serialize model classes via `XSerializer.toMap`
else if (isModelClass(field.type)) {
}
buf.write("'$alias': $serializedRepresentation");
}