Customized Serialization
- During default serialization, there may be a chance of loss of information due to the transient keyword.
- Hence during default serialization, there may be a chance of loss of information because of transient keyword.
- To recover this loss of information we should go for customized serialization.
- We can implement customized serialization by using the following 2 methods.
- This method will be executed automatically at the time of serialization.
- Hence at the time of serialization if you want to perform any activity, we have to define that in this method only.
- This method will be executed automatically at the time of de-serialization.
- Hence at the time of de-serialization if we want to perform any activity, we have to define that in this method only.
Note:
- The above method are callback methods because these are executed automatically by the JVM.
- While performing which object serialization, we have to do extra work, in the corresponding class we have to define above method.
Ex 1.
Note:
Programmer can't call private method directly from outside of the class, but JVM can call private methods directly from outside of the class.