ZF-10211: Zend_Json_Server unable to pass objects

Issue Type: Improvement Created: 2010-07-23T08:34:30.000+0000 Last Updated: 2012-11-20T21:38:07.000+0000 Status: Open Fix version(s): Reporter: Kevin Schroeder (kschroeder) Assignee: None Tags: - Zend_Json_Server

Related issues: Attachments: - patch.txt


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 <


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 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

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.