Zend Framework

missing explicit null for error in response

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: Zend_Json_Server
  • Labels:
    None

Description

JSON-RPC specs say that there should be an explicit null for error key:

{{

{ "result": "Hello JSON-RPC", "error": null, "id": 1}

}}

However the error key is not set in ZF response:

{{

{ "result": "Hello JSON-RPC", "id": 1}

}}

This has the effect of throwing exceptions on many client libraries, including the python package from json-rpc.org.
Result key should be set as null as well when response has errors.

Suggested modification:

public function toJson()
{
if ($this->isError()) { $response = array( 'result' => null, 'error' => $this->getError()->toArray(), 'id' => $this->getId(), ); } else { $response = array( 'result' => $this->getResult(), 'id' => $this->getId(), 'error' => null ); }

if (null !== ($version = $this->getVersion())) { $response['jsonrpc'] = $version; }

require_once 'Zend/Json.php';
return Zend_Json::encode($response);
}

Activity

Hide
desfrenes added a comment -

any news on this one ?

Show
desfrenes added a comment - any news on this one ?
Hide
desfrenes added a comment -

Corrected response class

Show
desfrenes added a comment - Corrected response class
Hide
desfrenes added a comment -

I've added the correction as an attached file to this issue. So far I had no problem with it.

Show
desfrenes added a comment - I've added the correction as an attached file to this issue. So far I had no problem with it.
Hide
michael depetrillo added a comment -

added explicit null for error on success. also added explicity null for result on error.

Show
michael depetrillo added a comment - added explicit null for error on success. also added explicity null for result on error.

People

Vote (1)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: