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

[Serializer] Problem when serializing/deserializing empty arrays in xml #43193

Copy link
Copy link
Closed
@nikophil

Description

@nikophil
Issue body actions

Symfony version(s) affected: all? actually testing on 5.3.4

Description
When serializing an object with an empty array in xml and then deserializing this array into the same class, I encounter an error.

How to reproduce

class Test
{
     public function __construct(private SerializerInterface $serializer)
    {
    }

    public function test() {
        $object = new class(){
            public array $array = [];
        };
        
        $data = $this->serializer->serialize($object, 'xml');

        /**
         * $data is:
         * <?xml version="1.0"?>
         * <response>
         *  <array/>
         * </response>
         */

        $this->serializer->deserialize($data, get_class($object), 'xml');

        // :boom: 
        //  [Symfony\Component\Serializer\Exception\NotNormalizableValueException]                                  
        //  The type of the "array" attribute for class "class@anonymous" must be one of "array" ("string" given). 
    }

(NB: the error is not due to the anonymous class)

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.