Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7591645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:42:09+00:00 2026-05-30T20:42:09+00:00

Suppose we have an arbitrary graph represented by nodes and pointers like this: class

  • 0

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. 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:42:11+00:00Added an answer on May 30, 2026 at 8:42 pm

    I’ll address your last question first. The purpose of serialization is not cloning an object graph in memory. It is to transform an object graph to a stream of bytes in order to do things like saving in a file or sending across the wire. The deserialization process might be done on a different computer, at a different time, in a different process, or even by a non-Java program, so it is not a reasonable expectation to get references to the same objects as before. It is the structure and contents of the object graph that are being saved and later restored, not in-memory addresses. For precisely this reason, it does not make sense for all objects to be serializable. For instance, serializing a Thread is not going to be useful, because it is not going to be meaningful outside the current instance of a program.

    The magic behind automatic serialization is not very complex. Ignoring custom serialization methods that you can write for your own classes to precisely control the serialization and deserialization behavior, yes, the system will effectively traverse the object graph in order to generate a stream of bytes. This traversal is generally done as a DFS, not BFS. Basically, you ask Java to serialize an object, passing a reference to it. That reference will serve as the root of the object graph. From there, Java will recursively serialize the fields of that object. Of course, it does track circular references and writes out appropriate markings in the output stream so that the deserializer is able to hook up the pointers and recreate the structure as it was before.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose you have output like this: Word1 Word2 Word3 Word4 Where the number of
Suppose that I have a Java class with a static method, like so: class
Suppose you have this: <div>Area 1</div> <div style=clear:both;>Area 2</div> ... more arbitrary stuff <div
Suppose I have a table1 like this: id | itemcode ------------- 1 | c1
Suppose I have a stringbuilder in C# that does this: StringBuilder sb = new
Suppose I have a class module clsMyClass with an object as a member variable.
Suppose I have BaseClass with public methods A and B, and I create DerivedClass
Suppose we have: interface Foo { bool Func(int x); } class Bar: Foo {
Suppose we have some arbitrary positive number x . Is there a method to
Suppose I have a collection (of arbitrary size) of IQueryable<MyEntity> (all for the same

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.