It seems like at some point in the future that serialization will be deprecated.
Somebody told me that since serialization is binary and once you store it to persistent storage or if you're talking to another computer running Java with different versions of objects of the same class (such as using RMI), that this is problematic since once you start doing these types of things that it becomes difficult to add instance variables to your objects.
Doesn't this violate encapsulation?
I don't remember where I heard or read this, but there is some speculation that serialization as we know it now (to a binary format) should be replaced with serialization to XML files which are more well-suited to handling version differences.
Is there any truth to these rumors?
Kaydell [ June 03, 2007: Message edited by: Barry Gaunt ]
As I know serialization is useful specially when you need to transfer objects over the network so that you could reconstruct an object on the another machine. Serialization is for storing object state to the persistent storage for later use.
I see in various web applications, when it comes that you need to send an object of particular class over the network, your class must be serializable.
Not sure what you say, that XML will replace binary transformation of object. As I know in Hibernate technology it happens.
Interesting point. I suppose it does to some degree. Having the requirement that the receiver must have the same version of the class as the sender adds version information to the public knowledge about the object.
When you start going beyond your JVM, say to a persistance tool or passing objects over a network, you can introduce a lot of details with that potential. The boundaries between the ideal object model and the non-OO world are always a bit messy.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Actually, you do not need to have the same class file on each end; you need to have compatible class files on each end. Serialization includes a versioning mechanism that allows you to modify your classes as needed and still be able to read old serialized data files. Google "serialversionuid".
JAXB is the most "official" way to do serialization to XML; there are loads of commercial and non-commercial tools that do it, too. XML serialization is handy for long-term storage and communication between Java and non-Java code. For communicating over a wire between Java programs, though, a binary wire format is always going to be most efficient. Whether its JRMP with serialization, or IIOP, or something else, there's a niche for it, and it's a different niche than is served by serialization to XML.