Closed
Description
Symfony version(s) affected: 3.4, 4.4
Description
When there is a collection with a single item which shall be deserialized to a string array, the serializer produces an error instead of an array with one string.
A very simliar bug, but for collections of objects, was already reported in #27279 and fixed in ac70edf
Fatal error: Uncaught Symfony\Component\Serializer\Exception\NotNormalizableValueException: The type of the "offices" attribute for class "App\Entities\Buildings" must be one of "array" ("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...', 'offices', 'only one office...', '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)
#3 .../symfony-collection-serializer-bug/Normalizer/AbstractObjectNormalizer.php on line 298
How to reproduce
https://github.com/mkrauser/symfony-collection-serializer-bug
Just run php src/serialize.php
Possible Solution
Just like in ac70edf, I'll create a PR
Additional context
Tested with php 7.2