[Serializer] ObjectNormalizer
breaks when used with PropertyInfoExtractorInterface
#54787
Labels
ObjectNormalizer
breaks when used with PropertyInfoExtractorInterface
#54787
Symfony version(s) affected
5.4.39, 6.4.7, 7.0.7
Description
In the following commit, a change was introduced to the
ObjectNormalizer
constructor signature.900d034
Now,
ObjectNormalizer
requiresPropertyInfoExtractorInterface
to be passed as last argument (or anull
value).This is aliased in framework to match
property_info
service.symfony/src/Symfony/Bundle/FrameworkBundle/Resources/config/property_info.php
Line 33 in c168c2c
So, under normal circumstances in an application that uses Symfony framework, this is filled with
PropertyInfoExtractorInterface
(when autowiring, for example).If
null
value is passed,ReflectionExtractor
object is created in it's stead.symfony/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php
Line 53 in c168c2c
However,
ReflectionExtractor
is not a representation ofPropertyInfoExtractorInterface
.symfony/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php
Line 39 in c168c2c
On the following line:
symfony/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php
Lines 177 to 178 in c168c2c
...the property that can contain either
PropertyInfoExtractorInterface
orReflectionExtractor
is used - a methodgetWriteInfo()
is called that exists only onReflectionExtractor
. This means thatPropertyInfoExtractorInterface
cannot be used and will cause a PHP error, which results in inability to denormalize that object.Ergo, in case of our app, we cannot use the
property_info
service (nor it's caching), and must fall back tonull
.How to reproduce
We have this error...
...happen when
ObjectNormalizer
is asked to denormalize an object of the following type:with data (partial extract):
The
ObjectNormalizer
service is defined as follows:Possible Solution
ObjectNormalizer
, in lieu of addingPropertyInfoExtractorInterface
toReflectionExtractor
, should perform checks against method presence to better inform developers about what is actually going on and/or a fallback should exist in cases where we are not dealing withReflectionExtractor
instance.Additional Context
No response
The text was updated successfully, but these errors were encountered: