Results 1 to 6 of 6
Thread: Class Version in Serialization
- 02-03-2010, 06:18 PM #1
Member
- Join Date
- Jan 2010
- Posts
- 4
- Rep Power
- 0
Class Version in Serialization
Hi,
Please let me clear about the following,
While serializing a class object, a unique version UID of data type long created by the compiler for the class file as version identifer.
Also that it is possible to define the serialVersionUID variable manuallly in the java code.
But, We know that static variables are not serialized. It means the version UID is not recorded in the class file.
Then what information is kept in the class file to identify the correctness of the class version details in the process of serialization and de-serialization.
Thanks in advance,
-
I am no expert in serialization, in fact far from it, but I believe that when you create a serialization file, a file header is written first that contains this information. I believe that it is not part of the serialized object itself, but part of the file.
Corrections from anyone more knowledgeable are most welcome!
- 02-03-2010, 08:31 PM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
Serialisable classes have a StreamUniqueIdentifier (SUID).
You may also declare a static field serialVersionUID as you say. If you do then it will be used as the SUID, otherwise some default mechanism will be used.
The serialVersionUID field is not persisted. It's a static field, and there's no point in saving the value of static things every time an object is persisted.
But the SUID is different. It's not a variable, or a field or any other part of the class ... it's the SUID. It is not saved as part of the stream's contents but whatever mechanism is used to persist the object must ensure that it is there so that when reading the stream "The stream format of each class is identified by the use of a Stream Unique Identifier (SUID)."
(Java Object Serialization Specification: 5 - Versioning of Serializable Objects)
[Edit]
This post took a while to compose and FB's wasn't there when I started... It isn't meant as one of the invited "expert" answers.Last edited by pbrockway2; 02-03-2010 at 08:35 PM.
- 02-03-2010, 09:13 PM #4
well, the serialVersionUID is special, in that even though it is static, it does get sent along with the class.
-
- 02-04-2010, 04:01 AM #6
Member
- Join Date
- Jan 2010
- Posts
- 4
- Rep Power
- 0
Clarification
Thanks to all,
So can I take the concept of SUID,like
Its not persisted as part of the object.
But its kept in the file as header info or something like that, along with serialized objects.
So whenever the objects are get de-serialized on the other end, the SUID info of the current class file is compared with the SUID info from the serialized object input file. If there is any mismatch then InvalidClassException is thrown.
Is it correct?
Similar Threads
-
Serialization
By thayalan in forum Advanced JavaReplies: 4Last Post: 08-03-2009, 10:22 PM -
Serialization
By vijay24805 in forum Threads and SynchronizationReplies: 1Last Post: 04-10-2009, 09:16 PM -
about serialization
By bishnu in forum New To JavaReplies: 0Last Post: 12-19-2008, 09:13 AM -
Need help using serialization
By xcallmejudasx in forum New To JavaReplies: 0Last Post: 12-02-2008, 08:23 PM -
What is Serialization and de-serialization in Java
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:47 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks