Closed
Description
Symfony version(s) affected
7.1
Description
I believe a BC Break has been introduced in #51514.
In Symfony <= 7.0, providing an empty array in serializer_groups
returned "nothing".
In Symfony 7.1, the same serializer_groups
returns all the properties of the object (the groups are ignored and is similar to providing *
)
How to reproduce
$groups = [];
if ($isOwner) {
$groups[] = 'OWNER'
}
if ($isAdmin) {
$groups[] = 'ADMIN'
}
$propertyNameCollectionFactory = $this->container->get(ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface::clas);
dump($propertyNameCollectionFactory->create(MyObject::class, ['serializer_groups' => $groups]));
Possible Solution
I believe the fix is to return []
when !$groupsHasBeenDefined
in https://github.com/symfony/symfony/pull/51514/files#diff-8183be74478a13fcda2e17124d559a29013d10f119805a6623a8a396edb70c76R42
My workaround is to use:
$groups = ['DOES_NOT_USE_THIS_GROUP'];
if ($isOwner) {
$groups[] = 'OWNER'
}
if ($isAdmin) {
$groups[] = 'ADMIN'
}
Additional Context
No response