10000 [Serializer] Fix using deserialization path 6.3 by HypeMC · Pull Request #53109 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Serializer] Fix using deserialization path 6.3 #53109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ protected function instantiateObject(array &$data, string $class, array &$contex
sprintf('Failed to create object because the class misses the "%s" property.', $constructorParameter->name),
$data,
['unknown'],
$context['deserialization_path'] ?? null,
$attributeContext['deserialization_path'] ?? null,
true
);
$context['not_normalizable_value_exceptions'][] = $exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public function denormalize(mixed $data, string $type, string $format = null, ar
sprintf('Failed to denormalize attribute "%s" value for class "%s": '.$e->getMessage(), $attribute, $type),
$data,
['unknown'],
$context['deserialization_path'] ?? null,
$attributeContext['deserialization_path'] ?? null,
false,
$e->getCode(),
$e
Expand Down
70 changes: 67 additions & 3 deletions src/Symfony/Component/Serializer/Tests/SerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ public function testCollectDenormalizationErrors(?ClassMetadataFactory $classMet
'expectedTypes' => [
'unknown',
],
'path' => 'php74FullWithConstructor',
'path' => 'php74FullWithConstructor.constructorArgument',
'useMessageForUser' => true,
'message' => 'Failed to create object because the class misses the "constructorArgument" property.',
],
Expand Down Expand Up @@ -1199,6 +1199,70 @@ public function testCollectDenormalizationErrors2(?ClassMetadataFactory $classMe
$this->assertSame($expected, $exceptionsAsArray);
}

public function testCollectDenormalizationErrorsWithoutTypeExtractor()
{
$json = '
{
"string": [],
"int": [],
"float": []
}';

$serializer = new Serializer([new ObjectNormalizer()], ['json' => new JsonEncoder()]);

try {
$serializer->deserialize($json, Php74Full::class, 'json', [
DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS => true,
]);

$this->fail();
} catch (\Throwable $th) {
$this->assertInstanceOf(PartialDenormalizationException::class, $th);
}

$this->assertInstanceOf(Php74Full::class, $th->getData());

$exceptionsAsArray = array_map(fn (NotNormalizableValueException $e): array => [
'currentType' => $e->getCurrentType(),
'expectedTypes' => $e->getExpectedTypes(),
'path' => $e->getPath(),
'useMessageForUser' => $e->canUseMessageForUser(),
'message' => $e->getMessage(),
], $th->getErrors());

$expected = [
[
'currentType' => 'array',
'expectedTypes' => [
'unknown',
],
'path' => 'string',
'useMessageForUser' => false,
'message' => 'Failed to denormalize attribute "string" value for class "Symfony\\Component\\Serializer\\Tests\\Fixtures\\Php74Full": Expected argument of type "string", "array" given at property path "string".',
],
[
'currentType' => 'array',
'expectedTypes' => [
'unknown',
],
'path' => 'int',
'useMessageForUser' => false,
'message' => 'Failed to denormalize attribute "int" value for class "Symfony\\Component\\Serializer\\Tests\\Fixtures\\Php74Full": Expected argument of type "int", "array" given at property path "int".',
],
[
'currentType' => 'array',
'expectedTypes' => [
'unknown',
],
'path' => 'float',
'useMessageForUser' => false,
'message' => 'Failed to denormalize attribute "float" value for class "Symfony\\Component\\Serializer\\Tests\\Fixtures\\Php74Full": Expected argument of type "float", "array" given at property path "float".',
],
];

$this->assertSame($expected, $exceptionsAsArray);
}

/**
* @dataProvider provideCollectDenormalizationErrors
*/
Expand Down Expand Up @@ -1250,7 +1314,7 @@ public function testCollectDenormalizationErrorsWithConstructor(?ClassMetadataFa
'expectedTypes' => [
'unknown',
],
'path' => null,
'path' => 'string',
'useMessageForUser' => true,
'message' => 'Failed to create object because the class misses the "string" property.',
],
Expand All @@ -1259,7 +1323,7 @@ public function testCollectDenormalizationErrorsWithConstructor(?ClassMetadataFa
'expectedTypes' => [
'unknown',
],
'path' => null,
'path' => 'int',
'useMessageForUser' => true,
'message' => 'Failed to create object because the class misses the "int" property.',
],
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Serializer/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"symfony/http-foundation": "^5.4|^6.0",
"symfony/http-kernel": "^5.4|^6.0",
"symfony/mime": "^5.4|^6.0",
"symfony/property-access": "^5.4|^6.0",
"symfony/property-access": "^5.4.4|^6.0.4",
"symfony/property-info": "^5.4.24|^6.2.11",
"symfony/uid": "^5.4|^6.0",
"symfony/validator": "^5.4|^6.0",
Expand Down
0