Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Symfony serializer does not map collections correctly #27279

Copy link
Copy link
Closed
@fhink

Description

@fhink
Issue body actions

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+

https://stackoverflow.com/questions/49816306/symfony-serializer-deserialise-xml-which-contains-an-element-with-variable-amoun

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.