Skip to content

FILTER_BOOL must be used with DISABLE_TYPE_ENFORCEMENT #57487

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

Closed
lowwa132 opened this issue Jun 21, 2024 · 2 comments
Closed

FILTER_BOOL must be used with DISABLE_TYPE_ENFORCEMENT #57487

lowwa132 opened this issue Jun 21, 2024 · 2 comments

Comments

@lowwa132
Copy link

Symfony version(s) affected

7.1.x

Description

If the context FILTER_BOOL is used alone, we may experience a NotNormalizableValueException exception like this:

The type of the "booleanProperty" attribute for class "App\MyDTO" must be one of "bool" ("string" given).

Adding DISABLE_TYPE_ENFORCEMENT context solves the issue but is counter intuitive.

How to reproduce

Here is the code I use:

$this->serializer->deserialize($binaryExcelFile, MyDTO::class . '[]', ExcelEncoder::FORMAT);
use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;

class MyDTO
{
    #[Serializer\Context([AbstractNormalizer::FILTER_BOOL => true, AbstractObjectNormalizer::DISABLE_TYPE_ENFORCEMENT => true])]
    public bool $booleanProperty;
}

I use a custom ExcelEncoder.

Possible Solution

With FILTER_BOOLalone, it fails in Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer::validateAndDenormalize, before Symfony\Component\Serializer\Normalizer\AbstractNormalizer::applyFilterBool is applied

Maybe the applyFilterBool should be called sooner?

Additional Context

No response

@mtarld
Copy link
Contributor

mtarld commented Sep 9, 2024

Hey @lowwa132, since #57541 has been merged, is your issue solved now?

@xabbuh
Copy link
Member

xabbuh commented Sep 13, 2024

Let’s close here for now. We can reopen if the linked PR did not actually solve it.

@xabbuh xabbuh closed this as completed Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants