@@ -317,6 +317,8 @@ protected function instantiateObject(array &$data, string $class, array &$contex
317317 foreach ($ constructorParameters as $ constructorParameter ) {
318318 $ paramName = $ constructorParameter ->name ;
319319 $ key = $ this ->nameConverter ? $ this ->nameConverter ->normalize ($ paramName , $ class , $ format , $ context ) : $ paramName ;
320+ $ attributeContext = $ this ->getAttributeDenormalizationContext ($ class , $ paramName , $ context );
321+ $ attributeContext ['deserialization_path ' ] = $ attributeContext ['deserialization_path ' ] ?? $ key ;
320322
321323 $ allowed = false === $ allowedAttributes || (\is_array ($ allowedAttributes ) && \in_array ($ paramName , $ allowedAttributes , true ));
322324 $ ignored = !$ this ->isAllowedAttribute ($ class , $ paramName , $ format , $ context );
@@ -329,10 +331,8 @@ protected function instantiateObject(array &$data, string $class, array &$contex
329331 $ params [] = $ data [$ paramName ];
330332 }
331333 } elseif ($ allowed && !$ ignored && (isset ($ data [$ key ]) || \array_key_exists ($ key , $ data ))) {
332- $ constructorContext = $ context ;
333- $ constructorContext ['deserialization_path ' ] = $ context ['deserialization_path ' ] ?? $ key ;
334334 try {
335- $ params [] = $ this ->createConstructorArgument ($ data [$ key ], $ key , $ constructorParameter , $ constructorContext , $ format );
335+ $ params [] = $ this ->createConstructorArgument ($ data [$ key ], $ key , $ constructorParameter , $ attributeContext , $ format );
336336 } catch (NotNormalizableValueException $ exception ) {
337337 if (!isset ($ context ['not_normalizable_value_exceptions ' ])) {
338338 throw $ exception ;
@@ -351,7 +351,6 @@ protected function instantiateObject(array &$data, string $class, array &$contex
351351 $ missingConstructorArguments [] = $ constructorParameter ->name ;
352352 }
353353
354- $ attributeContext = $ this ->getAttributeDenormalizationContext ($ class , $ paramName , $ context );
355354 $ constructorParameterType = 'unknown ' ;
356355 $ reflectionType = $ constructorParameter ->getType ();
357356 if ($ reflectionType instanceof \ReflectionNamedType) {
@@ -362,7 +361,7 @@ protected function instantiateObject(array &$data, string $class, array &$contex
362361 \sprintf ('Failed to create object because the class misses the "%s" property. ' , $ constructorParameter ->name ),
363362 null ,
364363 [$ constructorParameterType ],
365- $ attributeContext ['deserialization_path ' ] ?? null ,
364+ $ attributeContext ['deserialization_path ' ],
366365 true
367366 );
368367 $ context ['not_normalizable_value_exceptions ' ][] = $ exception ;
@@ -405,7 +404,7 @@ protected function getClassDiscriminatorResolvedClass(array $data, string $class
405404 return $ mappedClass ;
406405 }
407406
408- protected function createConstructorArgument ($ parameterData , string $ key , \ReflectionParameter $ constructorParameter , array & $ context , ?string $ format = null ): mixed
407+ protected function createConstructorArgument ($ parameterData , string $ key , \ReflectionParameter $ constructorParameter , array $ context , ?string $ format = null ): mixed
409408 {
410409 return $ this ->createAndValidateAttributeValue ($ constructorParameter ->name , $ parameterData , $ format , $ context );
411410 }
0 commit comments