Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8a33f53

Browse filesBrowse files
committed
[Serializer] Fix deserialization_path missing using contructor
1 parent a560853 commit 8a33f53
Copy full SHA for 8a33f53

File tree

2 files changed

+7
-12
lines changed
Filter options

2 files changed

+7
-12
lines changed

‎src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,14 @@ protected function instantiateObject(array &$data, string $class, array &$contex
351351
$missingConstructorArguments = [];
352352
$params = [];
353353
$unsetKeys = [];
354+
$objectDeserializationPath = $context['deserialization_path'] ?? null;
355+
354356
foreach ($constructorParameters as $constructorParameter) {
355357
$paramName = $constructorParameter->name;
356358
$key = $this->nameConverter ? $this->nameConverter->normalize($paramName, $class, $format, $context) : $paramName;
357359

360+
$context['deserialization_path'] = $objectDeserializationPath ? $objectDeserializationPath.'.'.$paramName : $paramName;
361+
358362
$allowed = false === $allowedAttributes || \in_array($paramName, $allowedAttributes);
359363
$ignored = !$this->isAllowedAttribute($class, $paramName, $format, $context);
360364
if ($constructorParameter->isVariadic()) {
@@ -410,13 +414,15 @@ protected function instantiateObject(array &$data, string $class, array &$contex
410414
sprintf('Failed to create object because the class misses the "%s" property.', $constructorParameter->name),
411415
$data,
412416
['unknown'],
413-
$context['deserialization_path'] ?? null,
417+
$objectDeserializationPath,
414418
true
415419
);
416420
$context['not_normalizable_value_exceptions'][] = $exception;
417421
}
418422
}
419423

424+
$context['deserialization_path'] = $objectDeserializationPath;
425+
420426
if ($missingConstructorArguments) {
421427
throw new MissingConstructorArgumentsException(sprintf('Cannot create an instance of "%s" from serialized data because its constructor requires the following parameters to be present : "$%s".', $class, implode('", "$', $missingConstructorArguments)), 0, null, $missingConstructorArguments);
422428
}
@@ -489,8 +495,6 @@ protected function denormalizeParameter(\ReflectionClass $class, \ReflectionPara
489495
*/
490496
protected function createChildContext(array $parentContext, string $attribute, ?string $format): array
491497
{
492-
$parentContext['deserialization_path'] = ($parentContext['deserialization_path'] ?? false) ? $parentContext['deserialization_path'].'.'.$attribute : $attribute;
493-
494498
if (isset($parentContext[self::ATTRIBUTES][$attribute])) {
495499
$parentContext[self::ATTRIBUTES] = $parentContext[self::ATTRIBUTES][$attribute];
496500
} else {

‎src/Symfony/Component/Serializer/Tests/SerializerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/SerializerTest.php
-9Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,15 +1024,6 @@ public function testCollectDenormalizationErrors(?ClassMetadataFactory $classMet
10241024
'useMessageForUser' => true,
10251025
'message' => 'Failed to create object because the class misses the "constructorArgument" property.',
10261026
],
1027-
[
1028-
'currentType' => 'string',
1029-
'expectedTypes' => [
1030-
'float',
1031-
],
1032-
'path' => 'php74FullWithTypedConstructor',
1033-
'useMessageForUser' => false,
1034-
'message' => 'The type of the "something" attribute for class "Symfony\Component\Serializer\Tests\Fixtures\Php74FullWithTypedConstructor" must be one of "float" ("string" given).',
1035-
],
10361027
[
10371028
'currentType' => 'string',
10381029
'expectedTypes' => [

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.