Most of you must be aware with the Serialization involving single object but have you ever thought what if the object has reference to other objects too. Will it be serialized? Will reference objects will be serialized?
Answer to these queries is yes, you don’t have to explicitly serialize reference objects. Let’s find out how this can be achieved.
What is Object Graph?
An Object Graph is the set of objects which will be serialized automatically, if the object which contains reference to them is serialized.
In other words, we can say that when we serialize any object and if it contains any other object reference then JVM serializes the object and as well as its object references.
Lets make it more clear with the help of a simple example.
Value of i after Serialization is 10 Value of j after Serialization is 20
Note: In object graph every object should be serializable. If at-least one object is not serializable then we will get runtime execution saying NonSerializableExecution.
This article is contributed by Somya Garg. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Java.util.BitSet class methods in Java with Examples | Set 2
- Shadowing of static functions in Java
- How does default virtual behavior differ in C++ and Java ?
- How are Java objects stored in memory?
- How are parameters passed in Java?
- Are static local variables allowed in Java?
- final variables in Java
- Default constructor in Java
- Assigning values to static final variables in Java
- Comparison of Exception Handling in C++ and Java
- Does Java support goto?
- Arrays in Java
- Inheritance and constructors in Java
- More restrictive access to a derived class method in Java
- Comparison of static keyword in C++ and Java