-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added hprose serialization support. #162
Conversation
非常感谢,我们会尽快进行测试 |
谢谢,hprose 远程调用协议跟 motan 的适配好像有点麻烦,还没看明白该怎么做,所以这个只是序列化的。如果能够把反序列化接口改成支持泛型的 Type(替换 Class),效果会更好一些。不过好像比较难改。 |
|
||
@Override | ||
public byte[] serialize(Object data) throws IOException { | ||
ByteBufferStream stream = HproseFormatter.serialize(data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有很多java bean对象的属性都是私有的,这里是不是可以这样修改?
ByteBufferStream stream = HproseFormatter.serialize(data, HproseMode.FieldMode, false);
@andot 我发现hprose序列化时有个local的cache,用来缓存上一次序列化的对象,当对象的属性值修改后再次序列化时,还会使用缓存的byte[],相当于修改没有生效。见HproseFormatter类
可以试一下下面的例子
class TestModel{ |
默认用 HproseMode.MemberMode 是为了跨语言,HproseMode.FieldMode 适合纯 Java 之间传输。因为私有字段的名字在跨语言方面是个障碍,比如对于不知道实现的人来说,私有字段是什么样的不好确定,也可能私有字段名会定义的很乱。而且私有字段在继承关系中,如果有同名字段,也会导致序列化结果不正确。所以,Hprose 推荐用户在定义需要传输的类型时,对于需要封装的属性,用 getter 和 setter,对于不需要封装的属性,可以用 getter 和 setter,也可以用 public 的字段,而且这样定义的类,也不要求必须实现 Serializable 接口了。这就是 MemberMode 的由来。 至于那个 ThreadLocal 的 cache,确实没想到会导致这个问题。因为在 hprose 的 rpc 中,并没有使用这个 HproseFormatter 类,而是直接使用的 HproseWriter 和 HproseReader。我可以把这块改成也使用 HproseWriter 和 HproseReader 来进行序列化反序列化,就不会有这个问题了。 |
@andot 功能已经测试完了,没有问题。
|
@rayzhang0603 非常感谢,已修改。 |
非常感谢! |
文档需要更新一下。 |
这个仅仅是添加了 Hprose 序列化支持,跟 hessian2、fastjson 一样。