I need to save objects – instances of classes – in my app like some filetype. How I can write own serializer/deserializer for it?
Or exist some easier way how to save objects to some filetype?
Using of io.serialization was commented as not so good solution for “real” app. Why?
Serialization is difficult when objects change (such as when new fields are added). Objects may not be initialized as you expect or may be missing some data. There are methods for handing this though and custom serialization can be implemented by creating a readObject and writeObject method for deserialization and serialization. Tools such as XStream http://x-stream.github.io/ also exist for serializing to XML. Depending on the actual data you need to persist, you may want to consider writing just the data you need and reading it back in, and loading up your objects, rather than writing out the entire object graphs via serialization.