Skip to content

[Serializer] Collect deserialization errors on enum cause TypeError #46977

Closed
@elliotbruneel

Description

@elliotbruneel

Symfony version(s) affected

6.1

Description

When i want to collect denomalization errors i got and a TypeError instead

How to reproduce

class SerializerIssueReport extends TestCase
{
    public function testCollectErrorsOnEnum()
    {
        $serializer = new Serializer(
            [
                new BackedEnumNormalizer(),
                new ObjectNormalizer(),
            ],
            ['json' => new JsonEncoder()]
        );

        $serializer->deserialize('{"test": "invalid"}', DummyObject::class, 'json', [
            DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS => true
        ]);
        
        $this->expectException(PartialDenormalizationException::class);
    }
}


class DummyObject {
    public function __construct(
        public TestEnum $test,
    )
    {
    }
}

enum TestEnum: String
{
    case Test = "test";
}

Result: TypeError: DummyObject::__construct(): Argument #1 ($test) must be of type TestEnum, string given

Possible Solution

No response

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