-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Fix property name usage for denormalization #34035
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 property name usage for denormalization #34035
Conversation
6da3264
to
e4244b2
Compare
Did you mix things up? Group „a“ is only existent in the code change but not in the example in the PR header 🤔 |
Yes indeed thanks I'll update |
src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
Outdated
Show resolved
Hide resolved
Should be for 3.4? |
|
245dc23
to
6afeb2b
Compare
The patch doesn't change anything related to that, but changes |
6afeb2b
to
4446b64
Compare
4446b64
to
39efcda
Compare
I've updated the patch @nicolas-grekas as I think that the real underlying issue was in the |
39efcda
to
8ca4a3f
Compare
Thank you @antograssiot. |
…antograssiot) This PR was squashed before being merged into the 4.3 branch (closes #34035). Discussion ---------- [Serializer] Fix property name usage for denormalization | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | Using the `@SerializedName()` and passing it an existing property name affects the deserialization even if `@Groups()` are not supposed to be involved. ## How to reproduce Given the following class ```php class Foo { /** * @group("list") */ private $bar; public function setBar($bar) { $this->bar = $bar; } public function getBar() { return $this->bar; } /** * @groups({"list:export"}) * @SerializedName("bar") */ public function getBarForExport() { return $this->bar.' Rocks'; } } ``` This allow us to change the content of the property based on the normalization context. ```php $obj = new Foo(); $obj->setBar('Api Platform'); $data = $normalizer->normalize($obj, null, ['groups' => ["list"]]); // $data => ['bar' => 'Api Platform'] as expected $data = $normalizer->normalize($obj, null, ['groups' => ["list:export"]]); // $data => ['bar' => 'Api Platform Rocks'] as expected $obj = $normalizer->denormalize(['bar' => 'Api Platform'], Foo::class, null, ['groups' => ['list']]); // $obj->getBar() would return null instead of 'Api Platform' as expected. ``` Commits ------- 8ca4a3f [Serializer] Fix property name usage for denormalization
This PR cannot be correct: the value that is put in the cache is now context-dependent, but the context is not used to compute the cache key. @antograssiot can you please have a look for a better fix? |
I'll send an update @nicolas-grekas |
…rter cache (antograssiot) This PR was merged into the 4.3 branch. Discussion ---------- [Serializer] Use context to compute MetadataAwareNameConverter cache | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | This is a follow up PR to #34035 to address @nicolas-grekas 's [comment](#34035 (comment)) The static cache has been re-introduced and the context is used to compute the cache key used for denormalization Commits ------- 0ac5346 [Serializer] Use context to compute MetadataAwareNameConverter cache
Using the
@SerializedName()
and passing it an existing property name affects the deserialization even if@Groups()
are not supposed to be involved.How to reproduce
Given the following class
This allow us to change the content of the property based on the normalization context.