Suppose we have an arbitrary graph represented by nodes and pointers like this:
class Node
{
public ValueType data;
public ArrayList<Node> adj;
}
Now, I want to take a copy of it or write/read it on the disk (AKA serialize/deserialize). I also know that it can be done using a search algorithm + associative arrays. And, it turns out that this method is called swizzling.
Here goes my question:
I have heard that in Java by declaring the class as Serializable, this feature is provided for you automatically. (which sounds like a magic to me!)
Is this statement correct? Does Java automatically run BFS to traverse the graph and swizzle the pointers? In other words, does serialize/deserialize clone the object for me? (a completely brand new object with the same structure but new nodes and updated pointers)
If yes, then what if in some cases I just want to copy the pointers? what if I want to serialize the object just to keep the original pointers?
I appreciate any comments on this. :-)