@@ -298,6 +298,8 @@ protected function instantiateObject(array &$data, string $class, array &$contex
298298 foreach ($ constructorParameters as $ constructorParameter ) {
299299 $ paramName = $ constructorParameter ->name ;
300300 $ key = $ this ->nameConverter ? $ this ->nameConverter ->normalize ($ paramName , $ class , $ format , $ context ) : $ paramName ;
301+ $ attributeContext = $ this ->getAttributeDenormalizationContext ($ class , $ paramName , $ context );
302+ $ attributeContext ['deserialization_path ' ] = $ attributeContext ['deserialization_path ' ] ?? $ key ;
301303
302304 $ allowed = false === $ allowedAttributes || (\is_array ($ allowedAttributes ) && \in_array ($ paramName , $ allowedAttributes , true ));
303305 $ ignored = !$ this ->isAllowedAttribute ($ class , $ paramName , $ format , $ context );
@@ -310,10 +312,8 @@ protected function instantiateObject(array &$data, string $class, array &$contex
310312 $ params [] = $ data [$ paramName ];
311313 }
312314 } elseif ($ allowed && !$ ignored && (isset ($ data [$ key ]) || \array_key_exists ($ key , $ data ))) {
313- $ constructorContext = $ context ;
314- $ constructorContext ['deserialization_path ' ] = $ context ['deserialization_path ' ] ?? $ key ;
315315 try {
316- $ params [] = $ this ->createConstructorArgument ($ data [$ key ], $ key , $ constructorParameter , $ constructorContext , $ format );
316+ $ params [] = $ this ->createConstructorArgument ($ data [$ key ], $ key , $ constructorParameter , $ attributeContext , $ format );
317317 } catch (NotNormalizableValueException $ exception ) {
318318 if (!isset ($ context ['not_normalizable_value_exceptions ' ])) {
319319 throw $ exception ;
@@ -332,7 +332,6 @@ protected function instantiateObject(array &$data, string $class, array &$contex
332332 $ missingConstructorArguments [] = $ constructorParameter ->name ;
333333 }
334334
335- $ attributeContext = $ this ->getAttributeDenormalizationContext ($ class , $ paramName , $ context );
336335 $ constructorParameterType = 'unknown ' ;
337336 $ reflectionType = $ constructorParameter ->getType ();
338337 if ($ reflectionType instanceof \ReflectionNamedType) {
@@ -343,7 +342,7 @@ protected function instantiateObject(array &$data, string $class, array &$contex
343342 \sprintf ('Failed to create object because the class misses the "%s" property. ' , $ constructorParameter ->name ),
344343 null ,
345344 [$ constructorParameterType ],
346- $ attributeContext ['deserialization_path ' ] ?? null ,
345+ $ attributeContext ['deserialization_path ' ],
347346 true
348347 );
349348 $ context ['not_normalizable_value_exceptions ' ][] = $ exception ;
@@ -386,7 +385,7 @@ protected function getClassDiscriminatorResolvedClass(array $data, string $class
386385 return $ mappedClass ;
387386 }
388387
389- protected function createConstructorArgument ($ parameterData , string $ key , \ReflectionParameter $ constructorParameter , array & $ context , ?string $ format = null ): mixed
388+ protected function createConstructorArgument ($ parameterData , string $ key , \ReflectionParameter $ constructorParameter , array $ context , ?string $ format = null ): mixed
390389 {
391390 return $ this ->createAndValidateAttributeValue ($ constructorParameter ->name , $ parameterData , $ format , $ context );
392391 }
0 commit comments