Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.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 ourterms of service andprivacy 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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
carsonbot commentedJun 26, 2024
Hey! I see that this is your first PR. That is great! Welcome! Symfony has acontribution 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 OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
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
to6e657e8
CompareThank you@mazumba-nx. |
0af0679
intosymfony:7.1Uh oh!
There was an error while loading.Please reload this page.
…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 | MITImproves 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
.