Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Serializer] AbstractObjectNormalizer does not consider pseudo type false #45151

Copy link
Copy link
Closed
@ThomasNunninger

Description

@ThomasNunninger
Issue body actions

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.