Skip to content

Commit ecb2145

Browse files
bug #53959 [Serializer] Fix unknown types normalization type when know type (Myks92)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [Serializer] Fix unknown types normalization type when know type | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT When we use the normalizer with Promotion Constructor, a Non Normalizable Value Exception occurs with unknown type even when the type is known. This Pull request fix this error. Previously, a PR #53945 was proposed for extraction, in which `@mtarld` asked to change the target branch to 5.4 Commits ------- a4c2961 [Serializer] Fix unknown types normalization type when know type
2 parents 208f6d9 + a4c2961 commit ecb2145

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,16 @@ protected function instantiateObject(array &$data, string $class, array &$contex
410410
continue;
411411
}
412412

413+
$constructorParameterType = 'unknown';
414+
$reflectionType = $constructorParameter->getType();
415+
if ($reflectionType instanceof \ReflectionNamedType) {
416+
$constructorParameterType = $reflectionType->getName();
417+
}
418+
413419
$exception = NotNormalizableValueException::createForUnexpectedDataType(
414420
sprintf('Failed to create object because the class misses the "%s" property.', $constructorParameter->name),
415421
$data,
416-
['unknown'],
422+
[$constructorParameterType],
417423
$context['deserialization_path'],
418424
true
419425
);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ public function testCollectDenormalizationErrorsWithConstructor(?ClassMetadataFa
13081308
[
13091309
'currentType' => 'array',
13101310
'expectedTypes' => [
1311-
'unknown',
1311+
'string',
13121312
],
13131313
'path' => 'string',
13141314
'useMessageForUser' => true,
@@ -1317,7 +1317,7 @@ public function testCollectDenormalizationErrorsWithConstructor(?ClassMetadataFa
13171317
[
13181318
'currentType' => 'array',
13191319
'expectedTypes' => [
1320-
'unknown',
1320+
'int',
13211321
],
13221322
'path' => 'int',
13231323
'useMessageForUser' => true,
@@ -1548,7 +1548,7 @@ public function testPartialDenormalizationWithMissingConstructorTypes()
15481548
[
15491549
'currentType' => 'array',
15501550
'expectedTypes' => [
1551-
'unknown',
1551+
'string',
15521552
],
15531553
'path' => 'two',
15541554
'useMessageForUser' => true,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy