当前位置:网站首页>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.
边栏推荐
猜你喜欢

科研笔记(五) SLAC WiFi Fingerprint+ Step counter融合定位

SCI writing strategy - with common English writing sentence patterns

Research Notes (6) Indoor Path Planning Method Based on Environment Perception

Computer Basics

3D object detection dataset

吴恩达机器学习系列课程笔记——第八章:神经网络:表述(Neural Networks: Representation)

并发性,时间和相对性(1)-确定前后关系

已更新 联通 电信 tiny模式

JDBC再回顾

26. 如何判断一个对象是否存活?(或者GC对象的判定方法)?
随机推荐
RuoYi-App启动教程
Arduino框架下STM32F1/F4系列HID模式程序烧录教程
吴恩达机器学习系列课程笔记——第十五章:异常检测(Anomaly Detection)
CaDDN code debugging
LeetCode 23: 合并K个升序链表
P1192 台阶问题
OpenPCDet environment configuration of 3 d object detection and demo test
[Win11] PowerShell cannot activate Conda virtual environment
复制延迟案例(2)-读己之写
STM32 OLED显示屏
我们擅长的地方很多
多数据中心操作和检测并发写入
分布式系统的一致性与共识(1)-综述
无主复制系统(3)-Quorum一致性的局限性
C程序调试过程常见的错误
falco 【1】入门
线代005
CaDDN paper reading of monocular 3D target detection
科研笔记(五) SLAC WiFi Fingerprint+ Step counter融合定位
跑通CogView教程