[Serializer] Denormalizer doesn't support parsing string
value for boolean type or provides a way to extend denormalizer for scalar types
#42715
Labels
I am not really sure if this is a bug or feature request.
Symfony version(s) affected: All
Description
When using denormalizer with array input, and mapping to type with a boolean field doesn't support to parse string values like:
It is possible to go around this using attribute:
AbstractObjectNormalizer::DISABLE_TYPE_ENFORCEMENT => true
and using values like0
or1
but any other string value will always be cast to true because of PHP true logic (https://www.php.net/manual/en/types.comparisons.php).I thought I would be able to fix this issue by implementing a custom denormalizer, but type properties are not sent through denormalizers, and only the whole type.
This logic is implemented for xml/csv types:
symfony/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
Lines 432 to 441 in e34cd7d
I think the most appropriate way would be to implement a custom attribute to handle this specific case.
I will create a pull request with this implemented logic as an example of what I think can be done.
The text was updated successfully, but these errors were encountered: