Reputation: 1067
I have got a limited list of objects which I am serializing to storage using ObjectInputStream and ObjectOutputStream. I have come across suggestions not to use Serialize. Instead of serializing the list should I use xml approach using XmlSerializer and XmlPullParser? I will have to do additional steps of parsing xml with this approach.
Which is the correct approach?
Upvotes: 0
Views: 78
Reputation: 12745
TL;DR: There's no problem serializing your object if the user doesn't need to interact with it.
If the file you output needs to be shared, exported, or manually edited then it would be better to export as an XML. The use case for this could be to export a game character object and allow the user to edit some of their stats in the XML file or share their character with other users who could also edit it.
If the file you output is only used in your app, is never directly interacted with by the user, or is never even seen by the user then there is no reason you can't just serialize your object if that is what you prefer. A use case for this, similar to the first one, could be the saving of a game character that you don't want the user to be able to mess with. Serializing the object would make the file unreadable by the user and would prevent them from changing their stats in order to beat your game more easily.
The use cases are likely not relevant to your app but they do outline a few of the pros and cons of each approach.
Upvotes: 1