1515use Symfony \Component \PropertyAccess \PropertyAccess ;
1616use Symfony \Component \PropertyAccess \PropertyAccessorInterface ;
1717use Symfony \Component \PropertyInfo \Extractor \ReflectionExtractor ;
18+ use Symfony \Component \PropertyInfo \PropertyInfoExtractor ;
1819use Symfony \Component \PropertyInfo \PropertyInfoExtractorInterface ;
1920use Symfony \Component \PropertyInfo \PropertyTypeExtractorInterface ;
2021use Symfony \Component \PropertyInfo \PropertyWriteInfo ;
@@ -38,6 +39,7 @@ class ObjectNormalizer extends AbstractObjectNormalizer
3839
3940 protected $ propertyAccessor ;
4041 protected $ propertyInfoExtractor ;
42+ private $ writeInfoExtractor ;
4143
4244 private readonly \Closure $ objectClassResolver ;
4345
@@ -53,6 +55,7 @@ public function __construct(?ClassMetadataFactoryInterface $classMetadataFactory
5355
5456 $ this ->objectClassResolver = ($ objectClassResolver ?? static fn ($ class ) => \is_object ($ class ) ? $ class ::class : $ class )(...);
5557 $ this ->propertyInfoExtractor = $ propertyInfoExtractor ?: new ReflectionExtractor ();
58+ $ this ->writeInfoExtractor = new ReflectionExtractor ();
5659 }
5760
5861 public function getSupportedTypes (?string $ format ): array
@@ -189,8 +192,15 @@ protected function isAllowedAttribute($classOrObject, string $attribute, ?string
189192 return $ this ->propertyInfoExtractor ->isReadable ($ class , $ attribute ) || $ this ->hasAttributeAccessorMethod ($ class , $ attribute );
190193 }
191194
192- return $ this ->propertyInfoExtractor ->isWritable ($ class , $ attribute )
193- || ($ writeInfo = $ this ->propertyInfoExtractor ->getWriteInfo ($ class , $ attribute )) && PropertyWriteInfo::TYPE_NONE !== $ writeInfo ->getType ();
195+ if ($ this ->propertyInfoExtractor ->isWritable ($ class , $ attribute )) {
196+ return true ;
197+ }
198+
199+ if (($ writeInfo = $ this ->writeInfoExtractor ->getWriteInfo ($ class , $ attribute )) && PropertyWriteInfo::TYPE_NONE !== $ writeInfo ->getType ()) {
200+ return true ;
201+ }
202+
203+ return false ;
194204 }
195205
196206 private function hasAttributeAccessorMethod (string $ class , string $ attribute ): bool
0 commit comments