-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Description
Symfony version(s) affected
6.3
Description
RequestPayloadValueResolver
does not handle string and arrays properly, returning an empty / invalid dto even with all default values set.
class SearchDTO
{
public function __construct(
#[Assert\All([
new Assert\NotBlank(),
new Assert\Length(max: 50),
])]
public readonly array $brands = [],
#[Assert\All([
new Assert\NotBlank(),
new Assert\Length(max: 50),
])]
public readonly array $colors = [],
) {
}
}
How to reproduce
https://github.com/pedrocasado/dto
$ composer install
$ symfony serve
http://localhost:8000
http://localhost:8000/?brands[]=foo
http://localhost:8000/?brands=foo
DTO
class SearchDTO
{
public function __construct(
#[Assert\All([
new Assert\NotBlank(),
new Assert\Length(max: 50),
])]
public readonly array $brands = [],
#[Assert\All([
new Assert\NotBlank(),
new Assert\Length(max: 50),
])]
public readonly array $colors = [],
) {
}
}
Controller:
#[Route(path: '/', name: 'homepage')]
public function homepage(
#[MapQueryString] SearchDTO $searchDTO = new SearchDTO()
): Response {
dd($searchDTO);
}
Requests:
GET / (Ok, brands properly empty)
App\DTO\SearchDTO {#22310 ▼
+brands: []
+colors: []
}
GET /?brands[]=foo (Ok, brands properly set)
App\DTO\SearchDTO {#1053 ▼
+brands: array:1 [▼
0 => "foo"
]
+colors: []
}
GET /?brands=foo (Nok, SearchDTO empty, not even initialized. It does only work when passing "brands[]")
App\DTO\SearchDTO {#1053}
Possible Solution
Am i missing the serializer context?
Additional Context
No response