Skip to content

Commit

Permalink
[PHP-Symfony] Fix handling of null date-time parameter
Browse files Browse the repository at this point in the history
This fixes one of the issue described on #14930, namely that
the deserializeString method of the generated class JsmSerializer returns null
for other types of string, but not for date-time. Instead it returns a DateTime
which represents "now" (because that what `new DateTime(null)` does).

Consequently when an API declares a date-time parameter as non-required and
when that endpoint is called without that parameters, then the user code
would end up having "now" instead of "null" for this parameter.
  • Loading branch information
gturri committed Mar 12, 2023
1 parent d21b8d3 commit d90f309
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class JmsSerializer implements SerializerInterface
break;
case 'DateTime':
case '\DateTime':
return new DateTime($data);
return is_null($data) ? null :new DateTime($data);
default:
throw new RuntimeException(sprintf("Type %s is unsupported", $type));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private function deserializeString($data, string $type)
break;
case 'DateTime':
case '\DateTime':
return new DateTime($data);
return is_null($data) ? null :new DateTime($data);
default:
throw new RuntimeException(sprintf("Type %s is unsupported", $type));
}
Expand Down

0 comments on commit d90f309

Please sign in to comment.