Serialization
Serialization basic
The default use of jdk serialization will make the string escape
In actual development, when we want to store objects in redis, they must be serialized.
- Of course, if we convert the object to a json string, what is stored at this time is equivalent to a string. Non-serialization does not affect normal operation
- However, usually we have to serialize the objects we create.
- If we don’t serialize, store the object
In actual development, we may use json to convert, we don't want to use jdk serialization (the default is jdk serialization). At this point we need to use the configuration class.
We create a redisTemplate object to overwrite the original redis template object in the bean container.
Serialize various situations to distinguish
-
Case 1: The class is not serialized, and a javabean object is directly stored
. Result: an error is reported .b.
c.
d. No serialization, converted to json object storage. The console is normal, the black window is garbled
i.ii. ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210117120951829.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3poYW5nMTk5MDM4NDgyNTc=,size_16,color_FFFFFF,t_70) iii. ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210117121005205.png)
e. Serialization and conversion to json object storage. The black window is garbled.
i. -
Case 2: Class serialization, directly store a javebean object Result: The console is displayed normally, and the black window is garbled
a.b.
c.
-
Case 3 uses jackon serialization (custom serialization) The content is output normally.
a.b.
-
Situation 4 When using normally, we usually convert our objects into json storage, and do not directly store a certain java object.
a. We use the same method as above in use case three.
b. All objects must be serialized, that is, to achieve