1515
1616use ApiPlatform \Api \IriConverterInterface as LegacyIriConverterInterface ;
1717use ApiPlatform \Api \ResourceClassResolverInterface as LegacyResourceClassResolverInterface ;
18- use ApiPlatform \Exception \InvalidArgumentException ;
18+ use ApiPlatform \Exception \InvalidArgumentException as LegacyInvalidArgumentException ;
1919use ApiPlatform \Exception \ItemNotFoundException ;
2020use ApiPlatform \Metadata \ApiProperty ;
2121use ApiPlatform \Metadata \CollectionOperationInterface ;
22+ use ApiPlatform \Metadata \Exception \InvalidArgumentException ;
2223use ApiPlatform \Metadata \IriConverterInterface ;
2324use ApiPlatform \Metadata \Property \Factory \PropertyMetadataFactoryInterface ;
2425use ApiPlatform \Metadata \Property \Factory \PropertyNameCollectionFactoryInterface ;
@@ -244,7 +245,7 @@ public function denormalize(mixed $data, string $class, ?string $format = null,
244245 return $ this ->iriConverter ->getResourceFromIri ($ data , $ context + ['fetch_data ' => true ]);
245246 } catch (ItemNotFoundException $ e ) {
246247 throw new UnexpectedValueException ($ e ->getMessage (), $ e ->getCode (), $ e );
247- } catch (InvalidArgumentException $ e ) {
248+ } catch (LegacyInvalidArgumentException | InvalidArgumentException $ e ) {
248249 throw new UnexpectedValueException (\sprintf ('Invalid IRI "%s". ' , $ data ), $ e ->getCode (), $ e );
249250 }
250251 }
@@ -541,9 +542,14 @@ protected function denormalizeCollection(string $attribute, ApiProperty $propert
541542 $ childContext = $ this ->createChildContext ($ this ->createOperationContext ($ context , $ className ), $ attribute , $ format );
542543 $ collectionKeyTypes = $ type ->getCollectionKeyTypes ();
543544 foreach ($ value as $ index => $ obj ) {
545+ $ currentChildContext = $ childContext ;
546+ if (isset ($ childContext ['deserialization_path ' ])) {
547+ $ currentChildContext ['deserialization_path ' ] = "{$ childContext ['deserialization_path ' ]}[ {$ index }] " ;
548+ }
549+
544550 // no typehint provided on collection key
545551 if (!$ collectionKeyTypes ) {
546- $ values [$ index ] = $ this ->denormalizeRelation ($ attribute , $ propertyMetadata , $ className , $ obj , $ format , $ childContext );
552+ $ values [$ index ] = $ this ->denormalizeRelation ($ attribute , $ propertyMetadata , $ className , $ obj , $ format , $ currentChildContext );
547553 continue ;
548554 }
549555
@@ -554,7 +560,7 @@ protected function denormalizeCollection(string $attribute, ApiProperty $propert
554560 continue ;
555561 }
556562
557- $ values [$ index ] = $ this ->denormalizeRelation ($ attribute , $ propertyMetadata , $ className , $ obj , $ format , $ childContext );
563+ $ values [$ index ] = $ this ->denormalizeRelation ($ attribute , $ propertyMetadata , $ className , $ obj , $ format , $ currentChildContext );
558564 continue 2 ;
559565 }
560566 throw NotNormalizableValueException::createForUnexpectedDataType (\sprintf ('The type of the key "%s" must be "%s", "%s" given. ' , $ index , $ collectionKeyTypes [0 ]->getBuiltinType (), \gettype ($ index )), $ index , [$ collectionKeyTypes [0 ]->getBuiltinType ()], ($ context ['deserialization_path ' ] ?? false ) ? \sprintf ('key(%s) ' , $ context ['deserialization_path ' ]) : null , true );
@@ -590,7 +596,7 @@ protected function denormalizeRelation(string $attributeName, ApiProperty $prope
590596 );
591597
592598 return null ;
593- } catch (InvalidArgumentException $ e ) {
599+ } catch (LegacyInvalidArgumentException | InvalidArgumentException $ e ) {
594600 if (!isset ($ context ['not_normalizable_value_exceptions ' ])) {
595601 throw new UnexpectedValueException (\sprintf ('Invalid IRI "%s". ' , $ value ), $ e ->getCode (), $ e );
596602 }
0 commit comments