Serializing beans. Change in code makes old files unreadable.

A

Andoni

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.
 
K

Kenneth P. Turvey

Andoni said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,823
Latest member
Nadia88

Latest Threads

Top