Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

FILTER_BOOL must be used with DISABLE_TYPE_ENFORCEMENT #57487

Copy link
Copy link
Closed
@lowwa132

Description

@lowwa132
Issue body actions

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.