Skip to content

Commit

Permalink
[Serializer] Fix unknown types normalization type when know type
Browse files Browse the repository at this point in the history
  • Loading branch information
Myks92 authored and nicolas-grekas committed Feb 22, 2024
1 parent 02acd86 commit 05137a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion Normalizer/AbstractNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,16 @@ protected function instantiateObject(array &$data, string $class, array &$contex
continue;
}

$constructorParameterType = 'unknown';
$reflectionType = $constructorParameter->getType();
if ($reflectionType instanceof \ReflectionNamedType) {
$constructorParameterType = $reflectionType->getName();
}

$exception = NotNormalizableValueException::createForUnexpectedDataType(
sprintf('Failed to create object because the class misses the "%s" property.', $constructorParameter->name),
$data,
['unknown'],
[$constructorParameterType],
$context['deserialization_path'],
true
);
Expand Down
6 changes: 3 additions & 3 deletions Tests/SerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ public function testCollectDenormalizationErrorsWithConstructor(?ClassMetadataFa
[
'currentType' => 'array',
'expectedTypes' => [
'unknown',
'string',
],
'path' => 'string',
'useMessageForUser' => true,
Expand All @@ -1317,7 +1317,7 @@ public function testCollectDenormalizationErrorsWithConstructor(?ClassMetadataFa
[
'currentType' => 'array',
'expectedTypes' => [
'unknown',
'int',
],
'path' => 'int',
'useMessageForUser' => true,
Expand Down Expand Up @@ -1548,7 +1548,7 @@ public function testPartialDenormalizationWithMissingConstructorTypes()
[
'currentType' => 'array',
'expectedTypes' => [
'unknown',
'string',
],
'path' => 'two',
'useMessageForUser' => true,
Expand Down

0 comments on commit 05137a5

Please sign in to comment.