ZF-10211: Zend_Json_Server unable to pass objects
Description
Zend_Json_Server cannot handle objects that are returned from a result. So if a mapper returns an object it ends up not getting serialized. This patch will check to see if it's an object (or array of objects), check to see if it has a toArray() method and calls it, or casts it to (array) if toArray() doesn't exist.
Patch for library/Zend/Json/Server/Response.php: 181d180 < $result = $this->_convertObjectToArray($this->getResult()); 183c182
< 'result' => $result,
'result' => $this->getResult(),196,211d194 <
< protected function _convertObjectToArray($object) < { < if (is_object($object)) { < if (method_exists($object, 'toArray')) { < $object = $object->toArray(); < } else { < $object = (array)$object; < } < } else if (is_array($object)) { < foreach ($object as $key => $value) { < $object[$key] = $this->_convertObjectToArray($value); < } < } < return $object; < } 268d250 <
Comments
Posted by Kevin Schroeder (kschroeder) on 2010-07-23T10:44:52.000+0000
Non-mangled patch
Posted by Kevin Schroeder (kschroeder) on 2010-07-23T11:25:01.000+0000
Actually, scratch this. I have a new patch that works combining issue http://framework.zend.com/issues/browse/ZF-10213. Patch forthcoming.
Posted by Kevin Schroeder (kschroeder) on 2010-07-23T11:26:14.000+0000
Patch added to Zend_Json_Server that works with issue http://framework.zend.com/issues/browse/ZF-10213