-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Denormalize support for stdClass
#52850
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
base: 6.4
Are you sure you want to change the base?
Conversation
43d71df
to
0479a92
Compare
@dunglas could you make a code review and eventually merge the commit? |
0479a92
to
0238782
Compare
0238782
to
20a49a9
Compare
@nicolas-grekas Could you please make a review? |
Instead of hacking that in the ObjectNormalizer, I think this should rather be a new Normalizer |
@stof Good point. However, currently the normalizing process of stdClass is part of the same class - https://github.com/symfony/symfony/pull/52850/files#diff-397b4689ce56cc95e54911f6d78639bb3258a9ee9b36bfa06ec719e9635e6b1dR67 |
@stof I thought about it and think it should be part of the ObjectNormalizer.
@stof @dunglas Could you please make a review and eventually merge it? |
if we go that way, all core normalizers would be removed by bundling them into ObjectNormalizer, because BackedEnum or DateTime are also objects. ObjectNormalizer is not about being the implementation to use for all objects. It is the generic implementation used for objects that don't have another normalizer registered with a higher priority to take over the normalization with specific logic.
The JSON ODM does not use the ObjectNormalizer directly. It uses a Serializer with multiple normalizers registered in it. This means that they could totally register the new normalizer once it is available. They already did exactly that for the BackedEnumNormalizer and the UidNormalizer btw. |
I'm with @stof here. Adding special behavior for a specific class usually means we're adding a new normalizer. |
Agreed as well. The Plus, a |
We have this problem too: |
AKAIK, there is no ongoing work on that normalizer, so feel free to step in 🙂 |
Questions regarding "new normalizer". What about a class, that is a mixture of stdclass and object? <?php
declare(strict_types = 1);
use stdClass;
class Contact extends stdClass
{
public string $email = '';
} I am not sure if a new normalizer is the best solution here. But I will kick in and give feedback |
Hi.. The problem with an extra stdclass normalizer is the shared logic of stdclass objects and objects that extends stdclasses. It should be possible to extract the stdclass logic into a StdclassNormalizer and extend the ObjectNormalizer. Imho the ObjectNormalizer needs an overhaul, but this is an issue for later and not for now. Maybe, than it is possible to seperate the normalizers. |
stdClass
@dunglas |
What about acting directly on The actual behavior in PropertyAccessor is checking the following: I'm still not sure why we need that |
The property_exists is used to check whether a property with a |
@mtarld @alexandre-daubois |
Add support for denormalizing stdClass objects in Symfony serializer