From c47415a66f24eecf53b1f6972f037038d3e1079b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=B0=D1=80?= =?UTF-8?q?=D1=88=D0=BE=D0=BD=D0=BE=D0=BA?= Date: Mon, 1 Jul 2024 15:48:20 +0300 Subject: [PATCH] fix: add missing mapping of DateTime in multipart (#679) --- generator/lib/src/generator.dart | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/generator/lib/src/generator.dart b/generator/lib/src/generator.dart index 940d6564..30820a2a 100644 --- a/generator/lib/src/generator.dart +++ b/generator/lib/src/generator.dart @@ -1960,7 +1960,20 @@ ${bodyName.displayName} == null } else if (innerType?.element is ClassElement) { final ele = innerType!.element! as ClassElement; if (_missingToJson(ele)) { - throw Exception('toJson() method have to add to ${p.type}'); + if (_isDateTime(p.type)) { + final expr = [ + p.type.nullabilitySuffix == NullabilitySuffix.question + ? refer(p.displayName) + .nullSafeProperty('toIso8601String') + .call([]) + : refer(p.displayName) + .property('toIso8601String') + .call([]) + ]; + refer(dataVar).property('fields').property('add').call(expr); + } else { + throw Exception('toJson() method have to add to ${p.type}'); + } } else { blocks.add( refer(dataVar).property('fields').property('add').call([ @@ -2004,7 +2017,18 @@ ${bodyName.displayName} == null } else if (p.type.element is ClassElement) { final ele = p.type.element! as ClassElement; if (_missingToJson(ele)) { - throw Exception('toJson() method have to add to ${p.type}'); + if (_isDateTime(p.type)) { + final expr = [ + p.type.nullabilitySuffix == NullabilitySuffix.question + ? refer(p.displayName) + .nullSafeProperty('toIso8601String') + .call([]) + : refer(p.displayName).property('toIso8601String').call([]) + ]; + refer(dataVar).property('fields').property('add').call(expr); + } else { + throw Exception('toJson() method have to add to ${p.type}'); + } } else { if (contentType != null) { final uploadFileInfo = refer('$MultipartFile.fromString').call([