[Serializer] \TypeError
returned rather than a PartialDenormalizationException by PropertyNormalizer embedded into a Serializer
#60405
Labels
Symfony version(s) affected
7.2.X
Description
When attempting to denormalize an array of data into a
readonly
object using thePropertyNormalizer
within aSerializer
, a\TypeError
exception is thrown.Given that the following flags are set in the context:
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 anInvalidTypeException
.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
The text was updated successfully, but these errors were encountered: