Hello,
I want to save ANY kind of objects in a file and restore it anytime.
I use this for a object-oriented storage which I want to make. Serialization isn't a solution because many classes don't implement Serializable.
Thank you
Hello,
I want to save ANY kind of objects in a file and restore it anytime.
I use this for a object-oriented storage which I want to make. Serialization isn't a solution because many classes don't implement Serializable.
Thank you
Some objects were never meant to be stored and retrieved, and would break in spectacular ways if you tried. Anything that uses native resources (file handles, sockets, etc) is a prime example. That's why the Serializable interface exists; it serves partly as a guarantee that writing the object and reading it back won't cause bizarre issues.
If you wanted to try it anyway, you could conceivably use reflection to get the object's contents and stuff them into a file. But that would be a really bad idea.
If the objects are your own, simply implement Serializable. If they are owned by others then badger them to do likewise, or roll your own serialization mechanism (potentially using reflection).
Bear in mind that the latter process is very fragile (depending on the internals of another class), and may be completely inappropriate if the class contains non-serializable objects like file handles or sockets.