diff --git a/src/JMS/Serializer/JsonSerializationVisitor.php b/src/JMS/Serializer/JsonSerializationVisitor.php index e6916c846..d1781dd66 100644 --- a/src/JMS/Serializer/JsonSerializationVisitor.php +++ b/src/JMS/Serializer/JsonSerializationVisitor.php @@ -61,7 +61,7 @@ public function endVisitingObject(ClassMetadata $metadata, $data, array $type, C $rs = new \ArrayObject(); if (array() === $this->getRoot()) { - $this->setRoot($rs); + $this->setRoot(clone $rs); } } diff --git a/tests/JMS/Serializer/Tests/Serializer/JsonSerializationTest.php b/tests/JMS/Serializer/Tests/Serializer/JsonSerializationTest.php index 95ad559a4..558ae6c5a 100644 --- a/tests/JMS/Serializer/Tests/Serializer/JsonSerializationTest.php +++ b/tests/JMS/Serializer/Tests/Serializer/JsonSerializationTest.php @@ -175,6 +175,11 @@ public function testSerializeEmptyObject() $this->assertEquals('{}', $this->serialize(new Author(null))); } + public function testSerializeArrayWithEmptyObject() + { + $this->assertEquals('{"0":{}}', $this->serialize(array(new \stdClass()))); + } + protected function getFormat() { return 'json';