Results 1 to 6 of 6
  1. #1
    Gunas is offline Member
    Join Date
    Jan 2010
    Posts
    4
    Rep Power
    0

    Default 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,

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    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!

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    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.

  4. #4
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    well, the serialVersionUID is special, in that even though it is static, it does get sent along with the class.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by pbrockway2 View Post
    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.
    Nevertheless, it is a much better answer than mine, one that hopefully teaches the OP something, and definitely helped me. Thanks!

  6. #6
    Gunas is offline Member
    Join Date
    Jan 2010
    Posts
    4
    Rep Power
    0

    Default 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

  1. Serialization
    By thayalan in forum Advanced Java
    Replies: 4
    Last Post: 08-03-2009, 10:22 PM
  2. Serialization
    By vijay24805 in forum Threads and Synchronization
    Replies: 1
    Last Post: 04-10-2009, 09:16 PM
  3. about serialization
    By bishnu in forum New To Java
    Replies: 0
    Last Post: 12-19-2008, 09:13 AM
  4. Need help using serialization
    By xcallmejudasx in forum New To Java
    Replies: 0
    Last Post: 12-02-2008, 08:23 PM
  5. Replies: 0
    Last Post: 04-04-2008, 02:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •