From 5fda5ab08b8a197af834c00b5c0d084876a5e0c6 Mon Sep 17 00:00:00 2001 From: Tyler Sommer Date: Wed, 19 Jun 2013 11:28:48 -0700 Subject: [PATCH 1/2] Added failing test for serializing an array containing an empty object --- .../Serializer/Tests/Serializer/JsonSerializationTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/JMS/Serializer/Tests/Serializer/JsonSerializationTest.php b/tests/JMS/Serializer/Tests/Serializer/JsonSerializationTest.php index 474cc825e..8e8db1d16 100644 --- a/tests/JMS/Serializer/Tests/Serializer/JsonSerializationTest.php +++ b/tests/JMS/Serializer/Tests/Serializer/JsonSerializationTest.php @@ -173,6 +173,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'; From 3a151d193accfa46ae97ce9919ac248026e20089 Mon Sep 17 00:00:00 2001 From: Tyler Sommer Date: Wed, 19 Jun 2013 11:30:11 -0700 Subject: [PATCH 2/2] JsonSerializationVisitor now clones the root element --- src/JMS/Serializer/JsonSerializationVisitor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JMS/Serializer/JsonSerializationVisitor.php b/src/JMS/Serializer/JsonSerializationVisitor.php index 200d418cf..2db33dd58 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); } }