Skip to content

Commit

Permalink
fixes: #365;
Browse files Browse the repository at this point in the history
fix: Correct encoding of DateTime and Enum fields in toJson(), ensuring proper JSON response generation
  • Loading branch information
atharvapalaskar committed May 28, 2024
1 parent 60d1af7 commit d7cde03
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions bin/src/generate_output.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ extension on Generator {
Method generateToJsonMethod(dmmf.OutputType output) {
Expression generateValueExpression(Expression value, dmmf.OutputField field,
[bool nullable = true]) {

if ((field.outputType.location == dmmf.TypeLocation.scalar &&
field.outputType.type == 'Json') ||
field.outputType.location == dmmf.TypeLocation.outputObjectTypes) {
Expand All @@ -52,6 +53,18 @@ extension on Generator {

return call([]);
}
else if(field.outputType.location == dmmf.TypeLocation.scalar &&
field.outputType.type == 'DateTime') {
final call = nullable
? value.nullSafeProperty('toIso8601String')
: value.property('toIso8601String');
return call([]);
}
else if(field.outputType.location == dmmf.TypeLocation.enumTypes) {
return nullable
? value.nullSafeProperty('name')
: value.property('name');
}

return value;
}
Expand Down

0 comments on commit d7cde03

Please sign in to comment.