4 Replies Latest reply on Dec 22, 2009 8:23 PM by 843790

    Serialization after package path changed

    843790
      So, I had working code, but then decided to reorganize my class structure a bit. My object "TriggerProject" was moved from package 'triggerhelper' to 'triggerhelper.dataHolders'. The class itself is serializable and I was able to write it to a file and open it up with no problems - before I changed package names. As of now however, I get a ClassCastException because the serialized file assumed the Object was from the original package. This is not impeding me on moving forward, because I know the newly created files will save and open correctly - but it just got me curious wondering if there was a way to fix it. Like, if there was some way to cast the old package path to my new one.

      Forgive my ill-knowledge of the subject if the answer is completely obvious.

      -the code that breaks-
      //aFile is of type File...
      TriggerProject openedProject = null;
      FileInputStream fis = null;
      ObjectInputStream in = null;
      try{
        fis = new FileInputStream(aFile);
        in = new ObjectInputStream(fis);
        openedProject = (TriggerProject) in.readObject(); // <-- ClassCastException
        in.close();
      }//catch etc...