Skip to content

[Serializer] \TypeError returned rather than a PartialDenormalizationException by PropertyNormalizer embedded into a Serializer #60405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
delamotte-pierrick opened this issue May 12, 2025 · 0 comments

Comments

@delamotte-pierrick
Copy link

Symfony version(s) affected

7.2.X

Description

When attempting to denormalize an array of data into a readonly object using the PropertyNormalizer within a Serializer, a \TypeError exception is thrown.
Given that the following flags are set in the context:

DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS => true,
AbstractObjectNormalizer::DISABLE_TYPE_ENFORCEMENT => true,

I would have expected a PartialDenormalizationException instead. Is this the intended behavior?

How to reproduce

I made a small boilerplate to reproduce the bug HERE

Possible Solution

To address the issue, we should wrap the code in a try/catch block that catches the \TypeError and rethrows it as an InvalidTypeException.

In my REPRODUCER, I added two tests to demonstrate the fix: one is a temporary workaround that I'm currently using, and the other represents the solution I believe should be the definitive fix.

Additional Context

I'm currently using

  • PHP: 8.4.4;
  • symfony/normalizer: 7.2;

I use the flags

  • DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS => true
  • AbstractObjectNormalizer::DISABLE_TYPE_ENFORCEMENT => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants