В чем проблема?
package com.javarush.task.task20.task2021;
import java.io.*;
/*
Сериализация под запретом
*/
public class Solution implements Serializable {
public static class SubSolution extends Solution {
public String name;
public SubSolution() {
}
public SubSolution(String name) {
this.name = name;
}
private static void writeObject() {
new NotSerializableException();
}
}
public static void main(String[] args) throws IOException, ClassNotFoundException {
SubSolution solution = new SubSolution("andrei");
//serializable
FileOutputStream fileOutputStream = new FileOutputStream("my_file");
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
objectOutputStream.writeObject(solution);
fileOutputStream.close();
objectOutputStream.close();
// deserializable
FileInputStream fileInputStream = new FileInputStream("my_file");
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
SubSolution solution1 = (SubSolution) objectInputStream.readObject();
fileInputStream.close();
objectInputStream.close();
}
}