Closed
Description
Symfony version(s) affected: 4.1.0
Description
When there is a collection with a single item, the serializer creates produces an error instead of an array with one object.
Fatal error: Uncaught Symfony\Component\Serializer\Exception\NotNormalizableValueException: The type of the key "company" must be "int" ("string" given). in /Users/f.hink/www/collection_mapping_bug/Normalizer/ArrayDenormalizer.php:57
Stack trace:
#0 /Users/f.hink/www/collection_mapping_bug/Serializer.php(172): Symfony\Component\Serializer\Normalizer\ArrayDenormalizer->denormalize(Array, 'App\\Entities\\Of...', 'xml', Array)
#1 /Users/f.hink/www/collection_mapping_bug/Normalizer/AbstractObjectNormalizer.php(271): Symfony\Component\Serializer\Serializer->denormalize(Array, 'App\\Entities\\Of...', 'xml', Array)
#2 /Users/f.hink/www/collection_mapping_bug/Normalizer/AbstractObjectNormalizer.php(202): Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer->validateAndDenormalize('App\\Entities\\Of...', 'office', Array, 'xml', Array)
#3 /Users/f.hink/www/collection_mapping_bug/Serializer.php(172): Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer->denorm in /Users/f.hink/www/collection_mapping_bug/Normalizer/ArrayDenormalizer.php on line 57
How to reproduce
https://github.com/fhink/symfony-collection-serializer-bug
Just run php src/serialize.php
Possible Solution
fhink/symfony-collection-serializer-bug@2f5984b
Additional context
Tested with PHP 7.1+