-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Add a ScalarDenormalizer #39140
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] Add a ScalarDenormalizer #39140
Conversation
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
3c9f914
to
88358c0
Compare
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.
👍
362eec7
to
40a8bf9
Compare
src/Symfony/Component/Serializer/Normalizer/ScalarDenormalizer.php
Outdated
Show resolved
Hide resolved
40a8bf9
to
684e179
Compare
adb6c07
to
85f1775
Compare
4fb5b4c
to
3b153ea
Compare
I understand and after fixing the different returns this PR is more of an improvement than a bugfix. It might be possible by checking if a denormalizer is available before trying to denormalize the scalar value, as done in this implementation. How should I proceed:
|
I think, that's the best way. |
Also if we fix the UnwrappingDenormalizer I think that its priority needs to be reviewed, it's the only one in symfony to be
|
My guess is that the priority is so high because this denormalizer does not rely on the type and must always be called first. The bug that was reported occurred because scalar values are handled directly in the serializer and therefore it has the priority over the |
312372c
to
e0920a2
Compare
Little update, while trying to remove the duplication between the First, the scalar denormalization is done directly in the Second, the To summarize there is two issues:
What we could do is:
But the step
To void this we need to find a way to fallback to the current behavior if we can't denormalize because:
It should be doable by adding an new exception like I would like to validate how you would suggest to process before starting anything on my side. |
Idk if this is relevant but you should also consider #30818 and the work around it. |
90f8671
to
98a0a54
Compare
98a0a54
to
b7ae71d
Compare
handle builtin types and not just scalars Looking towards the possible refactoring of the AbstractObjectNormalizer it will be more convenient to have a denormalizer capable of handling builtin types instead of just scalar ones. Except for `null`, `iterable`, `array` and `object` types: - `null` could be handled here with little work but I'm not sure it's a good idea - `iterable` does not provide enough information to validte the items so it might be better to not handle it so that the user gave a "better" type - `array` and `object`, it's simplier to not support them so that we don't have to deal with a complex handling of priority within the normalizers
b7ae71d
to
3fdd925
Compare
The goal is to use a denormalizer to handle scalar values instead of doing it directly in the
Serializer
class.This allows to:
UnwrappingDenormalizer
Serializer
code, e.g. specific behavior based on the formatTodos:
ScalarDenormalizer
as a service inFrameworkBundle
AbstractObjectDenormalizer
for more clarity