我正在编写一个 rpc 框架,但面临有关序列化的问题。
你知道在客户端和服务器之间转换请求,我应该有一个这样的请求类:
class Request {
// target service class
private Class<?> targetService;
// target service method
private String targetMethod;
// target method param types
private Class<?>[] targetParamTypes;
// the params
private Object[] targetParams;
// getters & setters & contructors
}
但:
对于该targetParams
领域,如果我使用 Gson 作为序列化工具,com.google.gson.internal.LinkedTreeMap cannot be cast to the.packages.to.MyClass
如果我将 POJO 放入 中targetParams
,对于通用问题,它会出错。
对于int
类,Gson 总是将其解析为 a Double
,所以我不能使用targetParamTypes[i].cast(targetParams[i])
强制将其强制转换为 Integer(Double 不能转换为 Integer),它很糟糕...
那么有人有解决问题的方法吗?如何使序列化/反序列化步骤快速准确?或者有什么推荐的工具吗?
我努力了:
Gson,之前遇到的问题
Kyro,编解码器系统很烂,我不知道如何序列化/反序列化 HashMap ......
protostuff,嗯,它不支持 Java 9+,我的环境是 Java 11,糟糕!
所以有什么建议吗?
qq_遁去的一_1
月关宝盒
相关分类