1
0
Fork 0
mirror of https://github.com/sourcegraph/jsonrpc2.git synced 2026-06-16 04:04:56 +02:00

Always omit params member from request when empty (#67)

With this commit, the JSON encoding of `Request` always omits the params
member when calling `Conn.Call`, `Conn.DispatchCall`, or `Conn.Notify`
with the `params` argument set to `nil`. This change also removes the
`OmitNilParams` call option that was added in commit 8012d496 (#62).

As of this commit, if users desire to send a JSON-RPC request with a
`params` value of `null`, then they may do so by explicitly setting the
`params` argument of `Conn.Call`/`Conn.DispatchCall`/`Conn.Notify` to
`json.RawMessage("null")`.
This commit is contained in:
Sam Herrmann 2023-02-22 03:53:44 -05:00 committed by GitHub
parent 6864d8cc6d
commit ae88a5e7c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 240 additions and 159 deletions

View file

@ -10,8 +10,7 @@ import (
)
func TestResponse_MarshalJSON_jsonrpc(t *testing.T) {
null := json.RawMessage("null")
b, err := json.Marshal(&jsonrpc2.Response{Result: &null})
b, err := json.Marshal(&jsonrpc2.Response{Result: &jsonNull})
if err != nil {
t.Fatal(err)
}
@ -60,7 +59,6 @@ func TestResponseUnmarshalJSON_Notif(t *testing.T) {
}
func TestResponse_MarshalUnmarshalJSON(t *testing.T) {
null := json.RawMessage("null")
obj := json.RawMessage(`{"foo":"bar"}`)
tests := []struct {
data []byte
@ -73,7 +71,7 @@ func TestResponse_MarshalUnmarshalJSON(t *testing.T) {
},
{
data: []byte(`{"id":123,"result":null,"jsonrpc":"2.0"}`),
want: jsonrpc2.Response{ID: jsonrpc2.ID{Num: 123}, Result: &null},
want: jsonrpc2.Response{ID: jsonrpc2.ID{Num: 123}, Result: &jsonNull},
},
{
data: []byte(`{"id":123,"jsonrpc":"2.0"}`),