-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Fix ObjectNormalizer
with property path
#57187
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 ObjectNormalizer
with property path
#57187
Conversation
|| $this->propertyInfoExtractor->isReadable($class, $attribute) || $this->hasAttributeAccessorMethod($class, $attribute); | ||
} | ||
|
||
if (str_contains($attribute, '.')) { |
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 don't know a better way to fix this. The $this->propertyAccessor->isWritable()
method expects an object, but the isAllowedAttribute()
method is called before the object is instantiated.
Perhaps the $this->propertyAccessor->isReadable()
check should be removed as well, and the method should simply return true
if the attribute contains a .
?
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.
Indeed, I think that when can only rely on the .
in the first place, as it'll stick a bit more with the legacy behavior.
But later on I do think that it can be great to be able to know if foo.bar.baz
is readable/writable only based on reflection, so we have a more accurate behavior.
thanks for taking a look at this. |
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.
Works for me as-is on 5.4.
@@ -194,7 +194,12 @@ protected function isAllowedAttribute($classOrObject, string $attribute, ?string | |||
$class = \is_object($classOrObject) ? \get_class($classOrObject) : $classOrObject; | |||
|
|||
if ($context['_read_attributes'] ?? true) { | |||
return $this->propertyInfoExtractor->isReadable($class, $attribute) || $this->hasAttributeAccessorMethod($class, $attribute); | |||
return (\is_object($classOrObject) && $this->propertyAccessor->isReadable($classOrObject, $attribute)) | |||
|| $this->propertyInfoExtractor->isReadable($class, $attribute) || $this->hasAttributeAccessorMethod($class, $attribute); |
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.
return (\is_object($classOrObject) && $this->propertyAccessor->isReadable($classOrObject, $attribute)) || $this->propertyInfoExtractor->isReadable($class, $attribute) || $this->hasAttributeAccessorMethod($class, $attribute);
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.
Done
works for me as well with a minor code style change |
62efed3
to
3857545
Compare
Thank you @HypeMC. |
Caused by #52917.
The
ObjectNormalizer::isAllowedAttribute()
method doesn't work with property paths, this is an attempt to fix the problem.