@@ -298,6 +298,8 @@ protected function instantiateObject(array &$data, string $class, array &$contex
298
298
foreach ($ constructorParameters as $ constructorParameter ) {
299
299
$ paramName = $ constructorParameter ->name ;
300
300
$ 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 ;
301
303
302
304
$ allowed = false === $ allowedAttributes || (\is_array ($ allowedAttributes ) && \in_array ($ paramName , $ allowedAttributes , true ));
303
305
$ ignored = !$ this ->isAllowedAttribute ($ class , $ paramName , $ format , $ context );
@@ -310,10 +312,8 @@ protected function instantiateObject(array &$data, string $class, array &$contex
310
312
$ params [] = $ data [$ paramName ];
311
313
}
312
314
} elseif ($ allowed && !$ ignored && (isset ($ data [$ key ]) || \array_key_exists ($ key , $ data ))) {
313
- $ constructorContext = $ context ;
314
- $ constructorContext ['deserialization_path ' ] = $ context ['deserialization_path ' ] ?? $ key ;
315
315
try {
316
- $ params [] = $ this ->createConstructorArgument ($ data [$ key ], $ key , $ constructorParameter , $ constructorContext , $ format );
316
+ $ params [] = $ this ->createConstructorArgument ($ data [$ key ], $ key , $ constructorParameter , $ attributeContext , $ format );
317
317
} catch (NotNormalizableValueException $ exception ) {
318
318
if (!isset ($ context ['not_normalizable_value_exceptions ' ])) {
319
319
throw $ exception ;
@@ -332,7 +332,6 @@ protected function instantiateObject(array &$data, string $class, array &$contex
332
332
$ missingConstructorArguments [] = $ constructorParameter ->name ;
333
333
}
334
334
335
- $ attributeContext = $ this ->getAttributeDenormalizationContext ($ class , $ paramName , $ context );
336
335
$ constructorParameterType = 'unknown ' ;
337
336
$ reflectionType = $ constructorParameter ->getType ();
338
337
if ($ reflectionType instanceof \ReflectionNamedType) {
@@ -343,7 +342,7 @@ protected function instantiateObject(array &$data, string $class, array &$contex
343
342
\sprintf ('Failed to create object because the class misses the "%s" property. ' , $ constructorParameter ->name ),
344
343
null ,
345
344
[$ constructorParameterType ],
346
- $ attributeContext ['deserialization_path ' ] ?? null ,
345
+ $ attributeContext ['deserialization_path ' ],
347
346
true
348
347
);
349
348
$ context ['not_normalizable_value_exceptions ' ][] = $ exception ;
@@ -386,7 +385,7 @@ protected function getClassDiscriminatorResolvedClass(array $data, string $class
386
385
return $ mappedClass ;
387
386
}
388
387
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
390
389
{
391
390
return $ this ->createAndValidateAttributeValue ($ constructorParameter ->name , $ parameterData , $ format , $ context );
392
391
}
0 commit comments