ZF-5685: Zend_Json_Server does not respect the JSON RPC protocol



I am French so, sorry for my bad English...

Zend_Json_Server does not respect the JSON RPC protocol. Here "", we can read this:

Procedure Call with named parameters:

--> {"jsonrpc": "2.0", "method": "subtract", "params": {"subtrahend": 23, "minuend": 42}, "id": 3} <-- {"jsonrpc": "2.0", "result": 19, "id": 3}

--> {"jsonrpc": "2.0", "method": "subtract", "params": {"minuend": 42, "subtrahend": 23}, "id": 4} <-- {"jsonrpc": "2.0", "result": 19, "id": 4}

Or the Zend_Json_Server does not make this. The order of the parameters is important but the protocol specify that the order of the parameters is not important (Look exeample)...

Zend_Json_Server must read the method arguments name for to sort the params correctly.


The 1.2 specification has never been officially adopted, and one area that has been especially contentious is the idea of parameter order. In fact, in the past week on the JSON-RPC lists, it was pointed out that supporting both unnamed and named parameters is something that's next to impossible to achieve in most languages. Zend_Json_Server, as a result, allows for either named keys, or an ordered array, and then passes them to the method -- and this is currently the recommendation that is being drafted in the 2.0 specification.

Actually... now that I look at the code again, I realize that named argument support is not currently implemented. I'm flagging this as an improvement.

Scheduling as "improvement", and marking as must have for 1.8.

If I understood, for the moment, Zend_Json_Server can do:

--> {"jsonrpc": "2.0", "method": "subtract", "params": {"subtrahend": 23, "minuend": 42}, "id": 3} <-- {"jsonrpc": "2.0", "result": 19, "id": 3}

--> {"jsonrpc": "2.0", "method": "subtract", "params": [23, 42], "id": 3} <-- {"jsonrpc": "2.0", "result": 19, "id": 3}

In these cases, the order of the parameters is important and must be the same that the order of the method parameters. Zend_Json_Server is ok for these cases.

Now, Zend_Json_Server can not do that:

--> {"jsonrpc": "2.0", "method": "subtract", "params": {"minuend": 42, "subtrahend": 23}, "id": 4} <-- {"jsonrpc": "2.0", "result": 19, "id": 4}

Here, the order is not respected. It is this case which is problematic.

Are you agree with me?

I have the same issue. Attached is a simple patch that corrects the issue in my simple usage.

I added throwing of an "exception" for invalid parameters but feel free to remove if deemed too much additional functionality for a minor release.

Thanks for the JSON Server module!

Rob Olmos Ender Technology Corp.

Patch to correct the order of named parameters before dispatching.

Maybe batched requests can also be added?!

I'm using zf 1.8.4 an the bug is still open. Probably there is a need to change the "fix version" or to fix the issue. Thank you.

"next minor version" means the next minor version we release. We change it to the actual fix version once the issue is fixed.

I'll try and get it in for 1.9; patches are easier to accept when they include unit tests, however.