What happens if we serialize and deserialize two objects which references to each other?
- by Seregwethrin
To make it more clear, this is a quick example:
class A implements Serializable { public B b; }
class B implements Serializable { public A a; }
A a = new A();
B b = new B();
a.b = b;
b.a = a;
So what happens if we serialize a and b objects into a file and deserialize from that file?
I thought we get 4 objects, 2 of each. Identical objects but different instances.
But I'm not sure if there's anything else or is it right or wrong.
If any technology needed to answer, please think based on Java.
Thank you.