-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Symfony\Component\Serializer\Normalizer\PropertyNormalizer is unable to construct object without properties #46280
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
Comments
Hey @olsavmic, what do you mean when you say "without any properties", can you provide a tiny example? |
Sure, when you try to serialize class without any properties:
If we remove this additional check from PropertyNormalizer, it can construct the object perfectly fine, including call to the constructor. Replacing I simply think that the following check from \Symfony\Component\Serializer\Normalizer\PropertyNormalizer::supports is not needed or can be made optional:
|
Indeed, I don't see any reason to enforce having at least one "non-static" property. IMHO, as you said, we might add a context value like Up for a PR? 😉 |
Hey, thanks for your report! |
Hello? This issue is about to be closed if nobody replies. |
Waiting for linked PR to be merged #46417 |
Hey, thanks for your report! |
@nicolas-grekas @dunglas ping The release of Symfony 7 is getting pretty close and the implementation of a fix for this issue has been approved as optional feature for v6 and default in v7 (#46417 (comment)). Would you consider reviewing and releasing this change? To overcome this limitation in the meantime, we're using a custom normalizer for empty objects, which introduces unnecessary logic and is not fully compatible with all the stuff that |
Uh oh!
There was an error while loading. Please reload this page.
Description
Symfony\Component\Serializer\Normalize\PropertyNormalizer
is unable to construct object without any properties due to the check inPropertyNormalizer::supportsNormalization
.I don't see any reason to enforce this except for preventing programmers' errors, especially since the ObjectNormalizer does not impose such restrictions.
I can see legit use-cases in places like message queues where all required information is present in the message header and hence the body can be empty.
I'd suggest making this restriction in PropertyNormalizer optional as it removing it entirely could result in backward-incompatible change for very specific configurations (eg. someone might want to fallback to GetSetMethodNormalizer in case PropertyNormalizer fails)
(Similar situation applies to
Symfony\Component\Serializer\Normalize\GetSetMethodNormalizer
)The text was updated successfully, but these errors were encountered: