序列化 - Redis缓存Java对象的问题
迷茫
迷茫 2017-04-17 17:34:34
0
3
452

一个java bean 我知道有两种序列化方案
1、使用Json序列化为字符串
2、使用ObjectOutputStream 序列化为byte[]

不知道各位是使用哪种方式进行序列化存储的?各有什么优缺点

我先抛砖引玉

使用Json序列化

优点:缓存数据便于查阅,都是String字符串
缺点:java bean对象修改后,之前存储的数据,反序列化时会对新增字段赋予默认值,往往会带来业务逻辑上的问题

使用ObjectOutputStream序列化

优点:可以通过serialVersionUID控制版本号,如果bean对象发生修改,反序列化不会成功,能够有效避免上面的缺点
缺点:存储结果不便于查阅

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(3)
巴扎黑

There are many issues that need to be considered during serialization, and there are many serialization solutions to choose from for these issues.
But depending on the scenario, some questions can be ignored.
Here is a good test, I hope it will be helpful to the subject: https://github.com/eishay/jvm-serializer...

Ty80

org.springframework.data.redis.serializer.JdkSerializationRedisSerializer
The default seems to be this serialization, right? Just use the default one.

阿神

For json, deserialization is not very practical for generic collections. Java's own serialization is heavy and slow, which is not ideal, so please consider a serialization framework such as protobuf. In actual use, the effect is still very ideal.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template