java.lang.Object
imagingbook.common.util.SerializationHelper
Helper class providing static methods for writing/reading serialized data to/from files. It is recommended to
serialize only data structures composed of standard Java types. Otherwise, if self-defined classes are reloaded,
classes of previously serialized objects may not match any more, causing a
ClassNotFoundException
to be
thrown.- Version:
- 2022/07/28
-
Method Summary
Modifier and TypeMethodDescriptionstatic Object
readObject
(File file) Reads an object from a serialization file.static String
writeObject
(Object obj, File file) Writes a serialized representation of an arbitrary Java object to a file.
-
Method Details
-
writeObject
Writes a serialized representation of an arbitrary Java object to a file.- Parameters:
obj
- the object to be serialized.file
- the file to write to.- Returns:
- the full path of the written file.
-
readObject
Reads an object from a serialization file. The return value must be cast to the appropriate type, which must be known.- Parameters:
file
- the file to read.- Returns:
- the object reconstructed from the file representation or null if unsuccessful.
-