From e68b23672a8e8e7975641cfea43898f0d5c20e9f Mon Sep 17 00:00:00 2001 From: ElisDN Date: Mon, 13 May 2024 19:37:09 +0300 Subject: [PATCH 1/2] [Serializer] Fix type for missing property --- Normalizer/AbstractNormalizer.php | 2 +- Tests/SerializerTest.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Normalizer/AbstractNormalizer.php b/Normalizer/AbstractNormalizer.php index 2192f8ac..256be49e 100644 --- a/Normalizer/AbstractNormalizer.php +++ b/Normalizer/AbstractNormalizer.php @@ -418,7 +418,7 @@ protected function instantiateObject(array &$data, string $class, array &$contex $exception = NotNormalizableValueException::createForUnexpectedDataType( sprintf('Failed to create object because the class misses the "%s" property.', $constructorParameter->name), - $data, + null, [$constructorParameterType], $context['deserialization_path'], true diff --git a/Tests/SerializerTest.php b/Tests/SerializerTest.php index 1fa29968..639d14e0 100644 --- a/Tests/SerializerTest.php +++ b/Tests/SerializerTest.php @@ -1045,7 +1045,7 @@ public function testCollectDenormalizationErrors(?ClassMetadataFactory $classMet 'message' => 'The type of the "string" attribute for class "Symfony\Component\Serializer\Tests\Fixtures\Php74Full" must be one of "string" ("null" given).', ], [ - 'currentType' => 'array', + 'currentType' => 'null', 'expectedTypes' => [ 'unknown', ], @@ -1306,7 +1306,7 @@ public function testCollectDenormalizationErrorsWithConstructor(?ClassMetadataFa 'message' => 'The type of the "bool" attribute for class "Symfony\\Component\\Serializer\\Tests\\Fixtures\\Php80WithPromotedTypedConstructor" must be one of "bool" ("string" given).', ], [ - 'currentType' => 'array', + 'currentType' => 'null', 'expectedTypes' => [ 'string', ], @@ -1315,7 +1315,7 @@ public function testCollectDenormalizationErrorsWithConstructor(?ClassMetadataFa 'message' => 'Failed to create object because the class misses the "string" property.', ], [ - 'currentType' => 'array', + 'currentType' => 'null', 'expectedTypes' => [ 'int', ], @@ -1420,7 +1420,7 @@ public function testCollectDenormalizationErrorsWithEnumConstructor() $expected = [ [ - 'currentType' => 'array', + 'currentType' => 'null', 'useMessageForUser' => true, 'message' => 'Failed to create object because the class misses the "get" property.', ], @@ -1546,7 +1546,7 @@ public function testPartialDenormalizationWithMissingConstructorTypes() $expected = [ [ - 'currentType' => 'array', + 'currentType' => 'null', 'expectedTypes' => [ 'string', ], From 06cd11ff947d9d88ea2f86d1e7ab9f9f9facc7e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anderson=20M=C3=BCller?= Date: Wed, 1 Feb 2023 13:19:44 +0100 Subject: [PATCH 2/2] [Serializer] Improve exception message in UnwrappingDenormalizer --- Context/Normalizer/UnwrappingDenormalizerContextBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Context/Normalizer/UnwrappingDenormalizerContextBuilder.php b/Context/Normalizer/UnwrappingDenormalizerContextBuilder.php index f06f6ac7..5beb4e98 100644 --- a/Context/Normalizer/UnwrappingDenormalizerContextBuilder.php +++ b/Context/Normalizer/UnwrappingDenormalizerContextBuilder.php @@ -45,7 +45,7 @@ public function withUnwrapPath(?string $unwrapPath): static try { new PropertyPath($unwrapPath); } catch (InvalidPropertyPathException $e) { - throw new InvalidArgumentException('The "%s" property path is not valid.', previous: $e); + throw new InvalidArgumentException(sprintf('The "%s" property path is not valid.', $unwrapPath), previous: $e); } return $this->with(UnwrappingDenormalizer::UNWRAP_PATH, $unwrapPath);