10000 Serializer does not map basic non-string types correctly in XML and CSV · Issue #33849 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Serializer does not map basic non-string types correctly in XML and CSV #33849
Closed
@mkrauser

Description

@mkrauser

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

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

      0