sourcegraph / jsonrpc2

Package jsonrpc2 provides a client and server implementation of JSON-RPC 2.0 (http://www.jsonrpc.org/specification)
MIT License
196 stars 62 forks source link

Response: Add omitempty tag for Result #14

Closed tchap closed 7 years ago

tchap commented 7 years ago

The 'result' key MUST be unset according when the error key is set. This is not what is happening right now. When the error is set, "result":null is returned in the response payload. This patch is fixing the issue by adding omitempty for the result field.

Fixes #13

felixfbecker commented 7 years ago

Totally, I think I actually met bugs because of this. Would this fix still allow to set result to null or an empty array?

keegancsmith commented 7 years ago

Totally, I think I actually met bugs because of this. Would this fix still allow to set result to null or an empty array?

Yes. You can make the Result point to a json.RawMessage which is just []byte("null").

We will have to test this a bit before deploying it at Sourcegraph.com though.

cc @sqs

keegancsmith commented 7 years ago

@tchap thanks so much for the fix.

tchap commented 7 years ago

Thanks for merging so quickly 👍