Skip to content

[Serializer] Fix CurrentType for missing property #54913

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

Merged
merged 1 commit into from
May 16, 2024
Merged
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 @@ -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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be $parameterData instead?

Copy link
Contributor Author

@ElisDN ElisDN May 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is $parameterData = $data[$key] statement in cases above. But in this case (with missing parameter) the $data[$key] value does not exist and $parameterData will be empty too.

[$constructorParameterType],
$context['deserialization_path'],
true
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/Serializer/Tests/SerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
Expand Down Expand Up @@ -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',
],
Expand All @@ -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',
],
Expand Down Expand Up @@ -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.',
],
Expand Down Expand Up @@ -1546,7 +1546,7 @@ public function testPartialDenormalizationWithMissingConstructorTypes()

$expected = [
[
'currentType' => 'array',
'currentType' => 'null',
'expectedTypes' => [
'string',
],
Expand Down
Loading