stdClasses are not allowed for JsonRpcResponse
Closed this issue · 1 comments
eyudkin commented
For now there is a condition:
JsonRpcResponse payload 'must only contain arrays and scalar values'
It looks incorrect because of json encoding/decoding at php side.
I can arrange with my RPC-api clients, that API will return structure like:
{
"messages: [] // list (array)
"context": {}, // object (key-valued)
}
But if I'll will use only arrays and will want to return an empty object:
function myDeliveryCallback($request) {
return [
'messages' => [], // want empty array
'context' => [], // want empty object
];
}
It will return me json:
{
"messages":[], // empty array
"context":[] // empty array too! But clients will await empty object from me.
}
So, looks like with current assertion I can not return empty object which will cause problems for clients, written on languages with strict typing (golang/c/etc).
I think, best solution is to allow stdClasses, because they are natively mapping to json-objects i.e. empty objects in empty stdClass case.
prolic commented
I suggest you do the following:
function myDeliveryCallback($request) {
return [
'messages' => [], // want empty array
'context' => null, // null can be treated as empty object
];
}