Hello !
I don’t understand why I'am getting 'null' when I'm doing deserealization here:
Here is my enum:
---
package enums.serialize;
import java.time.LocalDateTime;
public enum Data
{
INSTANCE;
private LocalDateTime now;
public void setTime()
{
now = LocalDateTime.now();
}
public void printSavedTime()
{
System.out.println(now);
}
}
---
And here is main program:
---
package enums.serialize;
import java.io.*;
public class Main
{
public static void main(String[] args) throws IOException, ClassNotFoundException
{
//Data.INSTANCE.setTime();
//saveData();
getSavedData();
}
public static void saveData() throws IOException
{
try(ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("./now.ser")))
{
oos.writeObject(Data.INSTANCE);
oos.flush();
}
}
public static void getSavedData() throws IOException, ClassNotFoundException
{
System.out.println(new File("./now.ser").exists());
try(ObjectInputStream ois = new ObjectInputStream(new FileInputStream("./now.ser")))
{
((Data) ois.readObject()).printSavedTime();
}
}
}
---
The output is:
true
null