-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[Serializer] fix inherited properties normalization #62007
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
Conversation
src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php
Outdated
Show resolved
Hide resolved
6c1755b to
ce1c53e
Compare
nicolas-grekas
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, here are some minor CS suggestions
src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php
Outdated
Show resolved
Hide resolved
8d8d206 to
4a93d86
Compare
|
I would suggest limiting the property lookup to the class the getter was declared in ( Otherwise the results could change by introducing new properties in child classes, which could cause confusion: class Base
{
private bool $test = false;
public function isTest(): bool
{
return $this->test;
}
public function setTest(bool $test): void
{
$this->test = $test;
}
}
class Child extends Base {
private bool $isTest = true;
}
$serializer = new Serializer([new ObjectNormalizer()], [new JsonEncoder()]);
echo $serializer->serialize(new Base(), 'json') . PHP_EOL; // {"test":false}
echo $serializer->serialize(new Child(), 'json') . PHP_EOL; // {"isTest":false}This is, of course, just a theoretical example, but I can't think of a case in which this behavior could be useful and starting at the most likely correct class would reduce the number of checks/iterations necessary considerably for classes with many inherited properties. Another thing: I think for consistency's sake the check in line 115 should behave the same way. |
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.
Hi, I don't have the rights to approve this, but the related bug #61988 is preventing us from updating the latest patch
So +1 on this one, it seems fine, but I'm not an expert 😅
The failing tests don't seem to be related to the PR though 🤔 Could there be some radon fails on some environments and re-running the tests would succeed?
4a93d86 to
7db7b29
Compare
@frozenbrain, thank you for the feedback, I've made the changes. |
7db7b29 to
45e4313
Compare
|
Thank you @Link1515. |
Introduce
hasParentProperty()to detect and use properties defined in parent classes.