mirror of
https://github.com/sourcegraph/jsonrpc2.git
synced 2026-06-19 05:30:03 +02:00
Make the RequestField.Value an interface{}
This change trades an extra JSON unmarshal in `Request.UnmarshalJSON` for several little casts, checks, and marshals.
This commit is contained in:
parent
f987817f79
commit
83d34e6888
3 changed files with 50 additions and 34 deletions
|
|
@ -39,7 +39,6 @@ func TestAnyMessage(t *testing.T) {
|
|||
func TestRequest_MarshalUnmarshalJSON(t *testing.T) {
|
||||
null := json.RawMessage("null")
|
||||
obj := json.RawMessage(`{"foo":"bar"}`)
|
||||
requestFieldValue := json.RawMessage(`"session"`)
|
||||
tests := []struct {
|
||||
data []byte
|
||||
want Request
|
||||
|
|
@ -58,7 +57,7 @@ func TestRequest_MarshalUnmarshalJSON(t *testing.T) {
|
|||
},
|
||||
{
|
||||
data: []byte(`{"id":123,"jsonrpc":"2.0","method":"m","sessionId":"session"}`),
|
||||
want: Request{ID: ID{Num: 123}, Method: "m", Params: nil, ExtraFields: []RequestField{{Name: "sessionId", Value: &requestFieldValue}}},
|
||||
want: Request{ID: ID{Num: 123}, Method: "m", Params: nil, ExtraFields: []RequestField{{Name: "sessionId", Value: "session"}}},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue