java - Serialization of a class inside the class -
i'm trying make class singleton have serialize method. objective serialize singleton in own function. there way serialize class inside class ?
here sample of tried :
public void serialize() {     singleton commit = this.getinstance();      try {         fileoutputstream fileout = new fileoutputstream(new config().getdatafile());         objectoutputstream out = new objectoutputstream(fileout);         out.writeobject(commit);         out.close();         fileout.close();     } catch (exception e) {         system.out.println("unable commit database changes.");         e.printstacktrace(system.out);     } }   and stack trace below :
unable commit database changes. java.io.notserializableexception: com.cuistot.data.singleton     @ java.io.objectoutputstream.writeobject0(objectoutputstream.java:1184)     @ java.io.objectoutputstream.writeobject(objectoutputstream.java:348)     @ [...].singleton.serialize(singleton.java:50)     [...]      
does class implement serializable?
looking @ source code for objectoutputstream.writeobject0, throws notserializableexception if object not serializable.
Comments
Post a Comment