Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| $params = []; | ||
| foreach ($constructorParametersas$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.
heregetAttributeDenormalizationContext() 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 OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Serializer/Tests/Normalizer/Features/ObjectDummyWithContextAttribute.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
mtarld commentedDec 15, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
It is quite strange that it do the exact opposite of what#46847 does |
nicolas-grekas commentedDec 15, 2022
Let's add a test case that covers the target behavior in#46847, this might help sort this out. |
nikophil commentedDec 15, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@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... |
dunglas left a comment
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
ogizanagi left a comment
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 thesuggestion 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.