英文:
JSONRPC format different between Jsonrpc4j and go's rpc/jsonrpc
问题
我在尝试使用net/jsonrpc包构建一个服务器和一个使用jsonrpc4j的Java客户端时遇到了一个问题。
问题是当错误发生时,golang的方法会返回错误并编码为json。
我在客户端得到了这个json对象:
{"id": -6028374044949000, "result": null, "error": "some error return message"}
在Java的json4j中,这个对象转换失败了。
根据http://www.jsonrpc.org/specification#error_object上的说明,错误字段必须是一个带有[code, message, date]字段的json对象,而golang的jsonrpc包不符合要求。
所以我很困惑如何解决这个问题。
是更换jsonrpc库,
还是将rpc方式替换为thrift/gRpc,
避免返回错误,而是在回复中发送错误并让Java检查响应,
还是只是编辑json4j或golang的源代码(对于这个选项我非常不确定)。
谢谢关注。
英文:
I was meet a problem when I tried used net/jsonrpc package to build a server and a Java client with jsonrpc4j
The problem is jsonrpc4j is when error happen, golang`s method will return error and encoding to json.
I got this json object in client
> {"id": -6028374044949000, "result": null, "error": "some error return message"}
This object cast failed in java's json4j.
http://www.jsonrpc.org/specification#error_object
After I checked the jsonrpc page, it is said the error field MUST a json object with fields [code, message, date], the golang jsonrpc package not meet the require.
So I`m confused how to solve this.
Change the jsonrpc lib,
Just replace the rpc way to thrift/gRpc,
Avoid to return error but send error in reply and let Java check the response,
Or just edited the json4j or golang's source code ( I'm very horrible about this option)
Thanks for watch.
答案1
得分: 0
如果你需要Go语言的JSON-RPC 2.0支持,你可以尝试使用https://github.com/powerman/rpc-codec。
英文:
If you need JSON-RPC 2.0 support for Go you can try https://github.com/powerman/rpc-codec
专注分享java语言的经验与见解,让所有开发者获益!
评论