当前位置:网站首页>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.
transientkeywords 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.
边栏推荐
- ROS visualization of 3D target detection
- 吴恩达机器学习系列课程笔记——第十六章:推荐系统(Recommender Systems)
- 吴恩达机器学习系列课程笔记——第九章:神经网络的学习(Neural Networks: Learning)
- 直播 | 7.30 ApacheCon Asia 2022 IOT/IIOT专题,IoTDB PMC 乔嘉林担任出品人
- 26. 如何判断一个对象是否存活?(或者GC对象的判定方法)?
- Qt处理传输协议数据时QByteArray添加多字节的使用案例
- Pycharm platform import scikit-learn
- 无主复制系统(3)-Quorum一致性的局限性
- Platts Analysis-MATLAB Toolbox Function
- MySQL存储函数详解
猜你喜欢
随机推荐
自定义一个下划线分词器
不会多线程还想进 BAT?精选 19 道多线程面试题,有答案边看边学
falco 【1】入门
斐波那契数列
HyperLynx中层叠设计实例
C语言:结构体总结
复制延迟案例(1)-最终一致性
【C语言程序】求直角三角形边长
复制延迟案例(3)-单调读
吴恩达机器学习系列课程笔记——第十五章:异常检测(Anomaly Detection)
micro-ros arduino esp32 ros2 笔记
论文速读:Homography Loss for Monocular 3D Object Detection
EasyCVR视频广场切换通道,视频播放协议异常的问题修复
Jetson Nano 2GB Developer Kit Installation Instructions
JDBC再回顾
如何解决QByteArray添加quint16双字节时错误?
热爱和责任
Research Notes (6) Indoor Path Planning Method Based on Environment Perception
internship:数据库表和建立的实体类及对应的枚举类之间的联系示例
UI自动化测试框架搭建——标记性能较差用例









