15
15
16
16
use ApiPlatform \Api \IriConverterInterface as LegacyIriConverterInterface ;
17
17
use ApiPlatform \Api \ResourceClassResolverInterface as LegacyResourceClassResolverInterface ;
18
- use ApiPlatform \Exception \InvalidArgumentException ;
18
+ use ApiPlatform \Exception \InvalidArgumentException as LegacyInvalidArgumentException ;
19
19
use ApiPlatform \Exception \ItemNotFoundException ;
20
20
use ApiPlatform \Metadata \ApiProperty ;
21
21
use ApiPlatform \Metadata \CollectionOperationInterface ;
22
+ use ApiPlatform \Metadata \Exception \InvalidArgumentException ;
22
23
use ApiPlatform \Metadata \IriConverterInterface ;
23
24
use ApiPlatform \Metadata \Property \Factory \PropertyMetadataFactoryInterface ;
24
25
use ApiPlatform \Metadata \Property \Factory \PropertyNameCollectionFactoryInterface ;
@@ -244,7 +245,7 @@ public function denormalize(mixed $data, string $class, ?string $format = null,
244
245
return $ this ->iriConverter ->getResourceFromIri ($ data , $ context + ['fetch_data ' => true ]);
245
246
} catch (ItemNotFoundException $ e ) {
246
247
throw new UnexpectedValueException ($ e ->getMessage (), $ e ->getCode (), $ e );
247
- } catch (InvalidArgumentException $ e ) {
248
+ } catch (LegacyInvalidArgumentException | InvalidArgumentException $ e ) {
248
249
throw new UnexpectedValueException (\sprintf ('Invalid IRI "%s". ' , $ data ), $ e ->getCode (), $ e );
249
250
}
250
251
}
@@ -541,9 +542,14 @@ protected function denormalizeCollection(string $attribute, ApiProperty $propert
541
542
$ childContext = $ this ->createChildContext ($ this ->createOperationContext ($ context , $ className ), $ attribute , $ format );
542
543
$ collectionKeyTypes = $ type ->getCollectionKeyTypes ();
543
544
foreach ($ value as $ index => $ obj ) {
545
+ $ currentChildContext = $ childContext ;
546
+ if (isset ($ childContext ['deserialization_path ' ])) {
547
+ $ currentChildContext ['deserialization_path ' ] = "{$ childContext ['deserialization_path ' ]}[ {$ index }] " ;
548
+ }
549
+
544
550
// no typehint provided on collection key
545
551
if (!$ collectionKeyTypes ) {
546
- $ values [$ index ] = $ this ->denormalizeRelation ($ attribute , $ propertyMetadata , $ className , $ obj , $ format , $ childContext );
552
+ $ values [$ index ] = $ this ->denormalizeRelation ($ attribute , $ propertyMetadata , $ className , $ obj , $ format , $ currentChildContext );
547
553
continue ;
548
554
}
549
555
@@ -554,7 +560,7 @@ protected function denormalizeCollection(string $attribute, ApiProperty $propert
554
560
continue ;
555
561
}
556
562
557
- $ values [$ index ] = $ this ->denormalizeRelation ($ attribute , $ propertyMetadata , $ className , $ obj , $ format , $ childContext );
563
+ $ values [$ index ] = $ this ->denormalizeRelation ($ attribute , $ propertyMetadata , $ className , $ obj , $ format , $ currentChildContext );
558
564
continue 2 ;
559
565
}
560
566
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
590
596
);
591
597
592
598
return null ;
593
- } catch (InvalidArgumentException $ e ) {
599
+ } catch (LegacyInvalidArgumentException | InvalidArgumentException $ e ) {
594
600
if (!isset ($ context ['not_normalizable_value_exceptions ' ])) {
595
601
throw new UnexpectedValueException (\sprintf ('Invalid IRI "%s". ' , $ value ), $ e ->getCode (), $ e );
596
602
}
0 commit comments