Closed
Description
Symfony version(s) affected: 3.4, 4.4
Description
In XML and CSV, all values are represented the same way, it is not possible to determine if a value is intended to be a string, int, float or boolean.
If something with non string properties (int, float, bool) is deserialized, an error is thrown:
PHP Fatal error: Uncaught Symfony\Component\Serializer\Exception\NotNormalizableValueException: The type of the "width" attribute for class "App\Entities\Building" must be one of "float" ("string" given). in ./symfony-collection-serializer-bug/Normalizer/AbstractObjectNormalizer.php:298
Stack trace:
#0 ./symfony-collection-serializer-bug/Normalizer/AbstractObjectNormalizer.php(202): Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer->validateAndDenormalize('App\\Entities\\Bu...', 'width', '10.1', 'xml', Array)
#1 ./symfony-collection-serializer-bug/Serializer.php(172): Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer->denormalize(Array, 'App\\Entities\\Bu...', 'xml', Array)
#2 ./symfony-collection-serializer-bug/Serializer.php(123): Symfony\Component\Serializer\Serializer->denormalize(Array, 'App\\Entities\\Bu...', 'xml', Array)
...
How to reproduce
I'll submit a PR with a failing test
Possible Solution
The values need to be converted cast to the expected type.
Additional context
Tested with php 7.2