Closed
Description
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_BOOL
alone, 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