当前位置:网站首页>What if some fields don't want to be serialized?
What if some fields don't want to be serialized?
2022-08-02 05:44:00 【The cudgel meat Alexander Lord】
First, let's wire up what is serialization?What is deserialization?
If we need to persist Java objects, such as saving Java objects in files, or transmitting Java objects over the network, serialization is required in these scenarios.
- Serialization
The process of converting a data structure or object into a stream of binary bytes.
- Deserialization
The process of converting the binary byte stream generated during serialization into a data result or object.
In the Java language, what we serialize is the object (Object), that is, the instantiated class (class), but in the half-faced object language such as C++, the struct (structure) defines the dataStructural types, and classes correspond to object types.
So, the main purpose of serialization is to transfer objects over the network or to store objects in the file system, database, or memory.
What if some fields do not want to be serialized?
For variables that do not want to be serialized, use the transient keyword to modify them.
transient
keywords do
Prevent the serialization of variables in the instance that are modified with this keyword; when the object is deserialized, the value of the variable modified by transient will not be persisted and restored.
- A few more notes about transient:
- transient can only modify variables, not classes and methods.
- Transient modified variables, the variable value will be set to the default value of the type after deserialization.For example, if it is a modified int type, the result after deserialization is 0.
- Because the static variable does not belong to any object (Object), it will not be serialized whether it is modified with the transient keyword or not.
边栏推荐
猜你喜欢
[Study Notes] How to Create an Operation and Maintenance Organizational Structure
jetracer_pro_2GB AI Kit system installation instructions
7亿听众背后的在线音频掘金故事
一次跳出最外层循环
Research Notes (8) Deep Learning and Its Application in WiFi Human Perception (Part 2)
Nexus 5 phone uses Nexmon tool to get CSI information
康威定律对于系统架构很重要吗?
吴恩达机器学习系列课程笔记——第十八章:应用实例:图片文字识别(Application Example: Photo OCR)
alibaba数据同步组件canal的实践整理
AFMG SysTune1.3.7使用图解
随机推荐
被大厂强制毕业,两个月空窗期死背八股文,幸好上岸,不然房贷都还不上了
CaDDN code debugging
什么是接触电流怎么测?
8月1日“海豹数藏”将全网首发民族英雄林则徐《四行行书》数字藏品!
6个月测试经验,面试跳槽狮子大开口要18K,只会点点点,给我整无语了。。
Arduino框架下 ESP32看门狗使用示例
P1192 台阶问题
最后写入胜利(丢弃并发写入)
Deep Blue Academy - Visual SLAM Lecture Fourteen - Chapter 5 Homework
无主复制系统(3)-Quorum一致性的局限性
C - The Domino Effect(dfs+回溯)
C语言:结构体总结
吴恩达机器学习系列课程笔记——第八章:神经网络:表述(Neural Networks: Representation)
ADSP21489工程中LDF文件配置详解
高等数学(第七版)同济大学 总习题三(前10题) 个人解答
多主复制的适用场景(1)-多IDC
Minecraft 1.18.1、1.18.2模组开发 23.3D动画盔甲制作
压缩包密码如何快速删除?
吴恩达机器学习系列课程笔记——第十四章:降维(Dimensionality Reduction)
jetracer_pro_2GB AI Kit system installation instructions