Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Symfony serializer does not map string-collections correctly in XML #33731

Closed
@mkrauser

Description

@mkrauser

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

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