fromJsonBody method
Implementation
String fromJsonBody() {
return checkNestedTypes(type!, (String cleanedType, bool isList, bool isListInList, bool isModel) {
final jsonVar = 'json[\'$name\']';
String conversion;
String modelFromJson([String jsonVar = 'e']) => '$cleanedType.fromJson($jsonVar as Map<String, dynamic>)';
if (isListInList) {
conversion =
'($jsonVar as List? ?? []).map((e) => (e as List? ?? []).map((e) => ${modelFromJson()}).toList()).toList()';
} else if (isList) {
if (isModel) {
conversion = '($jsonVar as List? ?? []).map((e) => ${modelFromJson()}).toList()';
} else {
conversion = '($jsonVar as List? ?? []).map((e) => e as $cleanedType).toList()';
}
} else if (isModel) {
conversion = modelFromJson(jsonVar);
} else if (isDatetime) {
conversion = 'DateTime.parse($jsonVar as String)';
} else {
conversion = '$jsonVar as $type';
}
if (isNullable) {
return '$name: $jsonVar != null ? $conversion : null';
} else {
return '$name: $conversion';
}
});
}