Skip to content

Commit a4c2961

Browse files
Myks92nicolas-grekas
authored andcommitted
[Serializer] Fix unknown types normalization type when know type
1 parent 5e773a8 commit a4c2961

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)