java - Object is altered during serialization? -
i trying serialize object, when deserialize set null. must missing something, please help. here serialize part:
public static void write(map<string, allat> m){ try { fileoutputstream fileout = new fileoutputstream("savefile.txt"); objectoutputstream out = new objectoutputstream(fileout); //m has correct parameters @ point out.writeobject(m); out.close(); fileout.close(); } catch(ioexception i) { i.printstacktrace(); } system.out.println("success."); }
here deserialize part:
public static map<string, allat> read(string path) { map<string, allat> m; try { fileinputstream filein = new fileinputstream(path); objectinputstream in = new objectinputstream(filein); m = (map<string, allat>) in.readobject(); in.close(); filein.close(); } catch(ioexception i) { system.out.println("io exception"); i.printstacktrace(); return null; } catch(classnotfoundexception c) { system.out.println("allat class not found"); c.printstacktrace(); return null; } return m; }
after calling read method, in resulting object set null/0. "allat" class implement java.io.serializable. thank help!