Closed
Description
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)