-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] fix context attribute with serializedName #48661
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
[Serializer] fix context attribute with serializedName #48661
Conversation
@@ -331,8 +331,8 @@ protected function instantiateObject(array &$data, string $class, array &$contex | |||
$params = []; | |||
foreach ($constructorParameters as $constructorParameter) { | |||
$paramName = $constructorParameter->name; | |||
$attributeContext = $this->getAttributeDenormalizationContext($class, $paramName, $context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here getAttributeDenormalizationContext()
was getting passed $key
which represents the serializedName, although we want the name of the property, to access its metadata
src/Symfony/Component/Serializer/Tests/Normalizer/Features/ObjectDummyWithContextAttribute.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Serializer/Tests/Normalizer/Features/ObjectDummyWithContextAttribute.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php
Outdated
Show resolved
Hide resolved
It is quite strange that it do the exact opposite of what #46847 does |
Let's add a test case that covers the target behavior in #46847, this might help sort this out. |
@nicolas-grekas code style fixed 👍 I'm not sure what else to test. #46847 says:
but we only pass through And the PR mentions #46525 which says:
which is exactly what my PR does and tests... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess things goes wrong in my mind when reading the bug fix in #46525 and proofreading #46680 after making the suggestion of adding the attribute-specific context to the name converter.
The diff between #46525 and this is #46525 is iterating the data keys to be denormalized to its properties, while this PR (and originally #46680) goes the other way around, iterating the constructor properties to be normalized to their counterpart in $data
.
Anyway, LGTM. Thank you @nikophil
Hello,
this PR fixes a bug where the
#[Context]
attribute is not read in denormalization process when it is used along with#[SerializedName]
in a constructor.In the test I provided, the two dates are not equals without the fix, although the same context is provided.