-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] [ObjectNormalizer] Use bool filter when FILTER_BOOL is set #57541
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] [ObjectNormalizer] Use bool filter when FILTER_BOOL is set #57541
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 |
src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php
Outdated
Show resolved
Hide resolved
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
d2a2cbd
to
6e657e8
Compare
Thank you @mazumba-nx. |
…ER_BOOL (DjordyKoert) This PR was submitted for the 7.2 branch but it was squashed and merged into the 7.1 branch instead. Discussion ---------- [Serializer] [ObjectNormalizer] Filter int when using FILTER_BOOL | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix ... | License | MIT Improves on #57541 to also allow numeric values `1` and `0` with `FILTER_BOOL => true` Currently attempting to use the Serializer component to deserialize to deserialize a `1` or `0` result in the following error: ``` The type of the "booleanProperty" attribute for class "App\MyDTO" must be one of "bool" ("int" given). ``` Commits ------- 5288eba [Serializer] [ObjectNormalizer] Filter int when using FILTER_BOOL
With 7.1 it is possible to map query booleans to php bool parameters (https://symfony.com/blog/new-in-symfony-7-1-misc-improvements-part-3#mapping-boolean-query-string-parameters). But as we found out, this only works when the DTO is initialized via
construct
. Otherwise theFILTER_BOOL
flag will be ignored and e.g. "false" will be deserialized astrue
.To fix this, I suggest to look for the
FILTER_BOOL
in the context and apply the filter, when the type isbool
and the data isstring
.