Closed
Description
Symfony version(s) affected
5.4
Description
When you have a PHP 8.0 object where an attribute uses the pseudo type false
(in a union type) you can't denormalize an array to that object.
How to reproduce
public function testDenormalizeFalsePseudoType(): void
{
if (version_compare(PHP_VERSION, '8.0.0') < 0) {
$this->markTestSkipped('This feature requires PHP 8.0');
}
// given a serializer that extracts the attribute types of an object via ReflectionExtractor
$propertyTypeExtractor = new PropertyInfoExtractor(
[],
[new ReflectionExtractor()],
[],
[],
[]
);
$objectNormalizer = new ObjectNormalizer(null, null, null, $propertyTypeExtractor);
$serializer = new Serializer([$objectNormalizer]);
// when denormalizing some data into an object where an attribute uses the false pseudo type
/** @var Php80Dummy $object */
$object = $serializer->denormalize(
[
'canBeFalseOrString' => false,
],
Php80Dummy::class
);
// then the attribute that declared false was filled correctly
$this->assertFalse($object->canBeFalseOrString);
}
Possible Solution
Pull request follows
Additional Context
No response