diff --git a/jsonrpc_base/jsonrpc.py b/jsonrpc_base/jsonrpc.py index 0c8ddca..9600f1e 100644 --- a/jsonrpc_base/jsonrpc.py +++ b/jsonrpc_base/jsonrpc.py @@ -193,7 +193,7 @@ def response_id(self): def serialize(self): """Generate the raw JSON message to be sent to the server""" data = {'jsonrpc': '2.0', 'method': self.method} - if self.params is not None: + if self.params: data['params'] = self.params if self.msg_id is not None: data['id'] = self.msg_id diff --git a/tests.py b/tests.py index 90a0d2e..a636dc6 100644 --- a/tests.py +++ b/tests.py @@ -62,11 +62,16 @@ def test_dumps(server): ) # test empty args dict assertSameJSON( - '''{"params": {}, "jsonrpc": "2.0", "method": "my_method_name", "id": - 1}''', + '''{"jsonrpc": "2.0", "method": "my_method_name", "id": 1}''', jsonrpc_base.Request( 'my_method_name', params={}, msg_id=1).serialize() ) + # test empty args array + assertSameJSON( + '''{"jsonrpc": "2.0", "method": "my_method_name", "id": 1}''', + jsonrpc_base.Request( + 'my_method_name', params=[], msg_id=1).serialize() + ) # test keyword args assertSameJSON( '''{"params": {"foo": "bar"}, "jsonrpc": "2.0", "method":