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

Skip to content

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

Closed
@nikophil

Description

@nikophil

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