1818use ApiPlatform \Metadata \Exception \AccessDeniedException ;
1919use ApiPlatform \Metadata \Exception \InvalidArgumentException ;
2020use ApiPlatform \Metadata \Exception \ItemNotFoundException ;
21+ use ApiPlatform \Metadata \Exception \PropertyNotFoundException ;
2122use ApiPlatform \Metadata \IriConverterInterface ;
2223use ApiPlatform \Metadata \Property \Factory \PropertyMetadataFactoryInterface ;
2324use ApiPlatform \Metadata \Property \Factory \PropertyNameCollectionFactoryInterface ;
@@ -276,10 +277,6 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a
276277 $ previousObject = $ this ->clone ($ objectToPopulate );
277278 $ object = parent ::denormalize ($ data , $ type , $ format , $ context );
278279
279- if (!$ this ->resourceClassResolver ->isResourceClass ($ type )) {
280- return $ object ;
281- }
282-
283280 // Bypass the post-denormalize attribute revert logic if the object could not be
284281 // cloned since we cannot possibly revert any changes made to it.
285282 if (null !== $ objectToPopulate && null === $ previousObject ) {
@@ -296,7 +293,13 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a
296293 // Revert attributes that aren't allowed to be changed after a post-denormalize check
297294 foreach (array_keys ($ data ) as $ attribute ) {
298295 $ attribute = $ this ->nameConverter ? $ this ->nameConverter ->denormalize ((string ) $ attribute ) : $ attribute ;
299- $ propertyMetadata = $ this ->propertyMetadataFactory ->create ($ resourceClass , $ attribute , $ options );
296+
297+ try {
298+ $ propertyMetadata = $ this ->propertyMetadataFactory ->create ($ resourceClass , $ attribute , $ options );
299+ } catch (PropertyNotFoundException ) {
300+ continue ;
301+ }
302+
300303 $ attributeExtraProperties = $ propertyMetadata ->getExtraProperties ();
301304 $ throwOnPropertyAccessDenied = $ attributeExtraProperties ['throw_on_access_denied ' ] ?? $ throwOnAccessDenied ;
302305 if (!\in_array ($ attribute , $ propertyNames , true )) {
@@ -500,12 +503,13 @@ protected function isAllowedAttribute(object|string $classOrObject, string $attr
500503 */
501504 protected function canAccessAttribute (?object $ object , string $ attribute , array $ context = []): bool
502505 {
503- if (!$ this ->resourceClassResolver ->isResourceClass ($ context ['resource_class ' ])) {
506+ $ options = $ this ->getFactoryOptions ($ context );
507+
508+ try {
509+ $ propertyMetadata = $ this ->propertyMetadataFactory ->create ($ context ['resource_class ' ], $ attribute , $ options );
510+ } catch (PropertyNotFoundException ) {
504511 return true ;
505512 }
506-
507- $ options = $ this ->getFactoryOptions ($ context );
508- $ propertyMetadata = $ this ->propertyMetadataFactory ->create ($ context ['resource_class ' ], $ attribute , $ options );
509513 $ security = $ propertyMetadata ->getSecurity () ?? $ propertyMetadata ->getPolicy ();
510514 if (null !== $ this ->resourceAccessChecker && $ security ) {
511515 return $ this ->resourceAccessChecker ->isGranted ($ context ['resource_class ' ], $ security , [
0 commit comments