Note that there are some explanatory texts on larger screens.

plurals
  1. POSerializing is not storing object data, only object references
    primarykey
    data
    text
    <p>I have a node tree built out of Node objects. They are more complex than the code I am showing but only have primitive or Serializable instance members.</p> <p>Assuming each Node can have up to 10 children the code looks a bit like so.</p> <pre><code>public class Node implements Serializable{ private static final long serialVersionUID = -848926218090221003L; private Node _parent; private boolean _hasParent; private Node[] _children; private int _childCount = 0; public Node(Node parent){ _children = new Node[10]; _parent = parent; _hasParent = (parent != null); } ... //Various accessors etc } </code></pre> <p>Now this tree is quite expensive to build but once it is done I write it to a file:</p> <pre><code>ObjectOutputStream serializedOuput = new ObjectOutputStream(new FileOutputStream(cacheFile)); serializedOuput.writeObject(tree); serializedOuput.close(); </code></pre> <p>When I am done caching the tree I make some irreversable changes to like trimming off unneeded branches.</p> <p>Then when I next need a base tree to work from I create a new tree object by reading in my serialized file.</p> <p>The problem...</p> <p>Creating the tree from the file seems to simply create a new object that points to the old one. In other words the modifications made after writing to file have also been made to the new tree.</p> <p>If I restart the app and try reading in the serialized file it returns null.</p> <p>So I seem to be serializing object references rather than the object itself, any ideas where I am going wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload