Index: tests/Zend/JsonTest.php =================================================================== --- tests/Zend/JsonTest.php (revision 14252) +++ tests/Zend/JsonTest.php (working copy) @@ -443,6 +443,18 @@ $this->assertEquals('{"firstName":"John","lastName":"Doe","email":"john@doe.com"}', $result); } + + public function testToJsonEmbededObjectSerialization() + { + $contacts = array( + new ToJsonClass() + ); + + Zend_Json::$useBuiltinEncoderDecoder = true; + $result = Zend_Json::encode($contacts); + + $this->assertEquals('[{"firstName":"John","lastName":"Doe","email":"john@doe.com"}]', $result); + } public function testIteratorToJson() { Index: library/Zend/Json/Encoder.php =================================================================== --- library/Zend/Json/Encoder.php (revision 14252) +++ library/Zend/Json/Encoder.php (working copy) @@ -133,6 +133,11 @@ $this->_visited[] = $value; } + if (method_exists($value, 'toJson')) + { + return $value->toJson(); + } + $props = ''; if ($value instanceof Iterator) {