@@ -361,7 +361,10 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
361361$ params =array_merge ($ params ,$ data [$ paramName ]);
362362 }
363363 }elseif ($ allowed && !$ ignored && (isset ($ data [$ key ]) ||array_key_exists ($ key ,$ data ))) {
364- $ params [] =$ this ->createConstructorArgument ($ data ,$ key ,$ constructorParameter ,$ context ,$ format );
364+ $ params [] =$ this ->createConstructorArgument ($ data [$ key ],$ key ,$ constructorParameter ,$ context ,$ format );
365+
366+ // Don't run set for a parameter passed to the constructor
367+ unset($ data [$ key ]);
365368 }elseif (isset ($ context [static ::DEFAULT_CONSTRUCTOR_ARGUMENTS ][$ class ][$ key ])) {
366369$ params [] =$ context [static ::DEFAULT_CONSTRUCTOR_ARGUMENTS ][$ class ][$ key ];
367370 }elseif ($ constructorParameter ->isDefaultValueAvailable ()) {
@@ -388,7 +391,7 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
388391 }
389392
390393/**
391- * @paramarray $data
394+ * @parammixed $parameterData
392395 * @param string $key
393396 * @param \ReflectionParameter $constructorParameter
394397 * @param array $context
@@ -400,13 +403,9 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
400403 * @throws RuntimeException
401404 * @throws MissingConstructorArgumentsException
402405 */
403- protected function createConstructorArgument (array & $ data ,string $ key ,\ReflectionParameter $ constructorParameter ,array &$ context ,string $ format =null )
406+ protected function createConstructorArgument ($ parameterData ,string $ key ,\ReflectionParameter $ constructorParameter ,array &$ context ,string $ format =null )
404407 {
405- $ parameterData =$ data [$ key ];
406408if (null ===$ parameterData &&$ constructorParameter ->allowsNull ()) {
407- // Don't run set for a parameter passed to the constructor
408- unset($ data [$ key ]);
409-
410409return null ;
411410 }
412411try {
@@ -415,19 +414,18 @@ protected function createConstructorArgument(array &$data, string $key, \Reflect
415414throw new LogicException (sprintf ('Cannot create an instance of %s from serialized data because the serializer inject in "%s" is not a denormalizer ' ,$ constructorParameter ->getClass (),static ::class));
416415 }
417416$ parameterClass =$ constructorParameter ->getClass ()->getName ();
418- $ parameterData =$ this ->serializer ->denormalize ($ parameterData ,$ parameterClass ,$ format ,$ this ->createChildContext ($ context ,$ constructorParameter ->name ));
417+
418+ return $ this ->serializer ->denormalize ($ parameterData ,$ parameterClass ,$ format ,$ this ->createChildContext ($ context ,$ constructorParameter ->name ));
419419 }
420420 }catch (\ReflectionException $ e ) {
421421throw new RuntimeException (sprintf ('Could not determine the class of the parameter "%s". ' ,$ key ),0 ,$ e );
422422 }catch (MissingConstructorArgumentsException $ e ) {
423423if (!$ constructorParameter ->getType ()->allowsNull ()) {
424424throw $ e ;
425425 }
426- $ parameterData =null ;
427- }
428426
429- // Don't run set for a parameter passed to the constructor
430- unset( $ data [ $ key ]);
427+ return null ;
428+ }
431429
432430return $ parameterData ;
433431 }