Serializing beans. Change in code makes old files unreadable.

Discussion in 'Java' started by Andoni, Aug 17, 2005.

  1. Andoni

    Andoni Guest

    Hi,

    Another question about serialization. I am looking to find something out
    which I know I could write a test program to solve but...

    I have a bean that holds a lot of data and has a few methods. These beans
    are written to file and the files are read after hours and processing is
    done on their contents. This means that I cannot change the bean until all
    files are processed as this will invalidate any files that have not yet been
    processed. As sometimes a file is put aside for processing another day, this
    can cause a problem.

    What I want to know is: If I create an inner class which actually holds the
    data, then will it's contract change when I make changes to the outer class?
    It's .class file should be the same so I suppose it should not but I'd like
    some confirmation before I go re-writing everything to fit this.

    Thanks in advance,
    Andoni.
    Andoni, Aug 17, 2005
    #1
    1. Advertising

  2. Andoni wrote:

    > What I want to know is: If I create an inner class which actually holds
    > the data, then will it's contract change when I make changes to the outer
    > class? It's .class file should be the same so I suppose it should not but
    > I'd like some confirmation before I go re-writing everything to fit this.


    I honestly don't know the answer to this question. My answer would be to
    try it and see.

    That said, any changes to the code or even the version of the virtual
    machine the code is running on, may invalidate the serialized data such
    that it is incompatible with the old data.

    The real solution if you want this data to survive code changes and JVM
    changes is to roll your own persistence or use a product that guarantees
    that the kind of changes you want to make will not break the file format.


    --
    Kenneth P. Turvey <>
    Kenneth P. Turvey, Aug 17, 2005
    #2
    1. Advertising

  3. Andoni

    Roedy Green Guest

    On Wed, 17 Aug 2005 14:19:39 +0100, "Andoni"
    <> wrote or quoted :

    >What I want to know is: If I create an inner class which actually holds the
    >data, then will it's contract change when I make changes to the outer class?


    see http://mindprod.com/jgloss/serialization.html#VERSIONING
    Roedy Green, Aug 19, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dag Sunde
    Replies:
    0
    Views:
    840
    Dag Sunde
    Dec 3, 2003
  2. Torsten Schmeissel
    Replies:
    0
    Views:
    408
    Torsten Schmeissel
    Apr 29, 2005
  3. Ellixis

    Unreadable source code

    Ellixis, May 23, 2004, in forum: C Programming
    Replies:
    1
    Views:
    473
    Chris Torek
    May 23, 2004
  4. Oldrider

    Unreadable xml files

    Oldrider, Dec 1, 2007, in forum: XML
    Replies:
    7
    Views:
    1,372
    Joe Kesselman
    Dec 2, 2007
  5. alex

    unreadable js code

    alex, Oct 11, 2005, in forum: Javascript
    Replies:
    11
    Views:
    149
Loading...

Share This Page