30 - Java Serialization using writeObject() and readObject() - Code Demo 2

Опубликовано: 11 Декабрь 2022
на канале: Rishi’s programming channel
102
2

‪@backstreetbrogrammer‬

--------------------------------------------------------------------------------
Chapter 13 - Serialization using writeObject() and readObject() - Code Demo 2
--------------------------------------------------------------------------------
If one of the reference object is not accessible, we had to mark it as transient.
While deserialization, the transient reference object will come as default value of null.

What can we do to somehow make sure that it matches the same object state when it was saved ?

Java serialization has a special mechanism just for this - a set of private methods we can implement such that it will be invoked automatically during serialization and deserialization.

These 2 special methods we define must have signatures that look EXACTLY like this:

For serialization
private void writeObject(ObjectOutputStream stream) {
// code for saving the object
}

For deserialization:
private void readObject(ObjectInputStream stream) {
// code for restoring the same object as it was saved although if its transient
}

By implementing these 2 methods, we can customize or control the default Java serialization process.

Also, we can call the methods like ObjectOutputStream.defaultWriteObject() and ObjectInputStream.defaultReadObject() to invoke the default Java serialization and deserialization process inside writeObject() and readObject() methods respectively.



Java Serialization Playlist:    • Java Serialization  
Java Serialization Github: https://github.com/backstreetbrogramm...

Dynamic Programming Playlist:    • Dynamic Programming  
Dynamic Programming Github: https://github.com/backstreetbrogramm...

#java #javadevelopers #javaprogramming #javaserialization


На этой странице сайта вы можете посмотреть видео онлайн 30 - Java Serialization using writeObject() and readObject() - Code Demo 2 длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Rishi’s programming channel 11 Декабрь 2022, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 102 раз и оно понравилось 2 зрителям. Приятного просмотра!