Best way to mark an inherited class as NOT serializable

If I inherit from a serializable class, but I do not want my class to be serializable; what's the best way to strictly ban serialization?

If there was a method in java.io.Serializable, maybe I could make an exception, but Serializable is empty.

+3
source share
1 answer

From the documentation

Serialization of an object can be prevented by implementing the writeObject and readObject methods that raise a NotSerializableException. The exception will depend on the ObjectOutputStream and abort the serialization process.

+7
source

Source: https://habr.com/ru/post/1736730/


All Articles