Code Comments
Programming Forum and web based access to our favorite programming groups.Do I have to implement the serializable interface? Is the default implementation of the serializable interface enough?
Post Follow-up to this messageOn Mon, 27 Sep 2004 11:23:13 +0530, Kiran Kumar Kamineni <kkumar@hp.com> wrote: > Do I have to implement the serializable interface? > Is the default implementation of the serializable interface enough? That depends on what your Objects are. If they consist only of primitives and Serializable Objects, yes. If not, no. -- Whom the gods wish to destroy they first call promising.
Post Follow-up to this messageKiran Kumar Kamineni wrote: > Do I have to implement the serializable interface? > Is the default implementation of the serializable interface enough? As a side note: Don't use the Object OutputStream unless you know what you are doing. It is not suited for making objects persistent as it doesn't handle versioning very well (store a class instance, change the class definition slightly, and your stored object is forever beyond reach). The ability to serialize objects was invented to handle object transfer over a network, but is widely misused as a persistence technology because it makes object save/retrieve so (apparently) simple. To store objects, use text files a'la properties files, XML or something similar. It takes a bit more effort as it needs custom save/load methods.
Post Follow-up to this message"Kiran Kumar Kamineni" <kkumar@hp.com> wrote in message news:<4157ab8e$1@usenet01.boi.hp.co m>... > Do I have to implement the serializable interface? > Is the default implementation of the serializable interface enough? Read my article on the subject: http://www.sys-con.com/story/?storyid=44199 Regards, Yakov
Post Follow-up to this messageJacob wrote: > Kiran Kumar Kamineni wrote: > > > As a side note: Don't use the Object OutputStream unless you know > what you are doing. It is not suited for making objects persistent > as it doesn't handle versioning very well (store a class instance, > change the class definition slightly, and your stored object is > forever beyond reach). > > The ability to serialize objects was invented to handle object > transfer over a network, but is widely misused as a persistence > technology because it makes object save/retrieve so (apparently) > simple. > > To store objects, use text files a'la properties files, XML > or something similar. It takes a bit more effort as it needs > custom save/load methods. Not necessarily. Consider using XMLEncoder and XMLDecoder (java.beans package) for easy automatic XML persistance. Still doesn't solve every possible case with complex objects, but works quite well nevertheless and handles versioning very well.
Post Follow-up to this messageGood point about serialization, Jacob. To overcome the pitfalls of ObjectOutputStream, you may want to look at XMLEncoder in the java.beans package. http://java.sun.com/j2se/1.4.2/docs...XMLEncoder.html
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.