Closed
Description
Symfony version(s) affected
6.3.0
Description
RequestPayloadValueResolver
always returns null when mapping query strings and query string is empty.
This is problematic when using a DTO where all arguments have default values, e.g.
class MyDto {
public function __construct(public string $foo = "bar")
{}
}
How to reproduce
Controller:
class MyDto {
public function __construct(public string $foo = "bar")
{}
}
class FooController extends AbstractController
{
#[Route("/foo", name: "foo", methods: ["GET"])]
public function getPaginated(
#[MapQueryString] MyDto $myDto,
): JsonResponse
{
return $this->json($myDto);
}
}
GET /foo
-> 404 HttpException
GET /foo?foo=baz
-> 200 {"foo": "baz"}
Possible Solution
Remove this early return and let the serializer decide what to do with an empty query string.
Additional Context
No response