Skip to content

Commit

Permalink
fix: add missing mapping of DateTime in multipart (#679)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sadhorsephile authored Jul 1, 2024
1 parent 7db7d08 commit c47415a
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions generator/lib/src/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -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([
Expand Down

0 comments on commit c47415a

Please sign in to comment.