简体   繁体   English

使用ProtoStuff在JDK 1.6和JDK 1.7上对Throwable进行序列化和反序列化

[英]Serialization and De-serialization of Throwable across JDK 1.6 and JDK 1.7 using ProtoStuff

We have two system one Running with JDK 1.6 and another with JDK 1.7. 我们有两个系统,一个运行JDK 1.6,另一个运行JDK 1.7。 To communicate between the two node we are using ProtoStuff Serialization to convert binary & transfer to other node where its again the binary is de-serialized. 为了在两个节点之间进行通信,我们使用ProtoStuff序列化将二进制文件转换并传输到另一个节点,在该节点中再次对二进制文件进行反序列化。

JDK 1.7 added new field 'suppressedExceptions', so now if we serialize the Throwable in JDK 1.7 in one node and transfer to another node its not able de-serialize & vice versa. JDK 1.7添加了新字段'suppressedExceptions',因此现在,如果我们在一个节点中序列化JDK 1.7中的Throwable,并将其不能反序列化的结果转移到另一个节点,反之亦然。

As two nodes uses different technology its not possible to migrate from JDK 1.6 to JDK 1.7 & JDK 1.7 to JDK 1.6. 由于两个节点使用不同的技术,因此无法将其从JDK 1.6迁移到JDK 1.7和将JDK 1.7迁移到JDK 1.6。

Is there any solution to solve this problem, Thanks in advance for the reply. 是否有解决此问题的解决方案,在此先感谢您的答复。

With Regards, Pavan 问候,帕万

Protostuff-runtime does not support backward compatibility between two class versions if new field is added to one of base classes. 如果将新字段添加到基类之一,则Protostuff运行时不支持两个类版本之间的向后兼容性。 This is caused by tag shift - when you add new field to base classe, all tag numbers in the childred classes are shifted. 这是由tag移位引起的-当您将新字段添加到基类时,子类中的所有tag号都会移位。 So, in general, there is no good solution for your problem. 因此,总的来说,没有解决您问题的好的方法。

But if you switch encoding to json, then problem should disappear. 但是,如果您将编码切换为json,那么问题应该会消失。 With protostuff-json , fields are stored using their names (instead of tags), so adding new field in the middle of class hierarchy should not be a problem anymore. 使用protostuff-json ,字段使用其名称(而不是标签)存储,因此在类层次结构的中间添加新字段不再是问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM