8000 bug #54913 [Serializer] Fix CurrentType for missing property (ElisDN) · symfony/symfony@a03ad0e · GitHub
[go: up one dir, main page]

Skip to content

Commit a03ad0e

Browse files
bug #54913 [Serializer] Fix CurrentType for missing property (ElisDN)
This PR was merged into the 5.4 branch. Discussion ---------- [Serializer] Fix CurrentType for missing property | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | | License | MIT If requested data does not contain any property: ```php class A { function __construct(string $a) {} } try { $a = $serializer->deserialize('{}', A::class, 'json'); } catch (NotNormalizableValueException $e) { var_dump($e->getMessage()); // "Failed to create object because class misses the 'a' property." var_dump($e->getPath()); // "a" var_dump($e->getExpectedTypes()); // ["string"] var_dump($e->getCurrentType()); // "array" } ``` then `getCurrentType` returns incorrect `"array"` value instead of expected `"null"` value. Commits ------- 5de8771 [Serializer] Fix type for missing property
2 parents e86406f + 5de8771 commit a03ad0e

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ protected function instantiateObject(array &$data, string $class, array &$contex
418418

419419
$exception = NotNormalizableValueException::createForUnexpectedDataType(
420420
sprintf('Failed to create object because the class misses the "%s" property.', $constructorParameter->name),
421-
$data,
421+
null,
422422
[$constructorParameterType],
423423
$context['deserialization_path'],
424424
true

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ public function testCollectDenormalizationErrors(?ClassMetadataFactory $classMet
10451045
'message' => 'The type of the "string" attribute for class "Symfony\Component\Serializer\Tests\Fixtures\Php74Full" must be one of "string" ("null" given).',
10461046
],
10471047
[
1048-
'currentType' => 'array',
1048+
'currentType' => 'null',
10491049
'expectedTypes' => [
10501050
'unknown',
10511051
],
@@ -1306,7 +1306,7 @@ public function testCollectDenormalizationErrorsWithConstructor(?ClassMetadataFa
13061306
'message' => 'The type of the "bool" attribute for class "Symfony\\Component\\Serializer\\Tests\\Fixtures\\Php80WithPromotedTypedConstructor" must be one of "bool" ("string" given).',
13071307
],
13081308
[
1309-
'currentType' => 'array',
1309+
'currentType' => 'null',
13101310
'expectedTypes' => [
13111311
'string',
13121312
],
@@ -1315,7 +1315,7 @@ public function testCollectDenormalizationErrorsWithConstructor(?ClassMetadataFa
13151315
'message' => 'Failed to create object because the class misses the "string" property.',
13161316
],
13171317
[
1318-
'currentType' => 'array',
1318+
'currentType' => 'null',
13191319
'expectedTypes' => [
13201320
'int',
13211321
],
@@ -1420,7 +1420,7 @@ public function testCollectDenormalizationErrorsWithEnumConstructor()
14201420

14211421
$expected = [
14221422
[
1423-
'currentType' => 'array',
1423+
'currentType' => 'null',
14241424
'useMessageForUser' => true,
14251425
'message' => 'Failed to create object because the class misses the "get" property.',
14261426
],
@@ -1546,7 +1546,7 @@ public function testPartialDenormalizationWithMissingConstructorTypes()
15461546

15471547
$expected = [
15481548
[
1549-
'currentType' => 'array',
1549+
'currentType' => 'null',
15501550
'expectedTypes' => [
15511551
'string',
15521552
],

0 commit comments

Comments
 (0)
0