diff --git a/Normalizer/AbstractNormalizer.php b/Normalizer/AbstractNormalizer.php index 30610911..ef9de38b 100644 --- a/Normalizer/AbstractNormalizer.php +++ b/Normalizer/AbstractNormalizer.php @@ -377,10 +377,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], $attributeContext['deserialization_path'] ?? null, true ); diff --git a/Tests/SerializerTest.php b/Tests/SerializerTest.php index dd9cbba4..55ec9afc 100644 --- a/Tests/SerializerTest.php +++ b/Tests/SerializerTest.php @@ -1303,7 +1303,7 @@ public function testCollectDenormalizationErrorsWithConstructor(?ClassMetadataFa [ 'currentType' => 'array', 'expectedTypes' => [ - 'unknown', + 'string', ], 'path' => 'string', 'useMessageForUser' => true, @@ -1312,7 +1312,7 @@ public function testCollectDenormalizationErrorsWithConstructor(?ClassMetadataFa [ 'currentType' => 'array', 'expectedTypes' => [ - 'unknown', + 'int', ], 'path' => 'int', 'useMessageForUser' => true, @@ -1621,7 +1621,7 @@ public function testPartialDenormalizationWithMissingConstructorTypes() [ 'currentType' => 'array', 'expectedTypes' => [ - 'unknown', + 'string', ], 'path' => 'two', 'useMessageForUser' => true,