title: How to deserialize object to new object with the same name?
body: <p>I have an application that previously stored some data by serializing the model object (<code>QuickNote</code>). This was then loaded by deserialization.</p>
  
  <p>However, I am updating the application to store the data by XML instead and I need to be able to import the old, serialized object for conversion. The new object, which does <strong>not</strong> implement <code>Serializable</code>, also has the same name though.(<code>QuickNote</code>).</p>
  
  <p>I am trying to deserialize the old <code>QuickNote</code> and store it into the new one using the follow code:</p>
  
  <pre><code>FileInputStream fileIn = new FileInputStream("data/quicknotes_user.dat");
  ObjectInputStream in = new ObjectInputStream(fileIn);
  List&lt;OldQuickNote&gt; newList = (List&lt;OldQuickNote&gt;) in.readObject();
  </code></pre>
  
  <p>Since the class name for the old serialized file is <code>QuickNote</code>, I get the error <code>java.io.InvalidClassException: model.QuickNote; class invalid for deserialization</code> due to the new class having the same name and not implementing <code>Serializable</code>.</p>
  
  <p>Is there a way to deserialize this <code>QuickNote</code> object into an <code>OldQuickNote</code> object? Both <code>QuickNote</code> and <code>OldQuickNote</code> are identical except that <code>QuickNote</code> no longer implements <code>Serializable</code> but <code>OldQuickNote</code> does.</p>
  
  <p>I did try to search for answers, but to be honest, I am not even sure how to search for this as I obviously made a poor design decision when electing to serialize the <code>QuickNote</code> object in the first place.</p>
  
  <p><strong>Caveats:</strong> </p>
  
  <ol>
  <li>I cannot change the object type (class name) for the serialized object as it is now residing on the user's systems.</li>
  <li>The new <code>QuickNote</code> object cannot be changed to implement <code>Serializable</code> because it is annotated and used for JAXB marshalling.</li>
  </ol>