i think i'll clarify part of the problem that's going on here... it's not strictly necessary, but if you're interested in "behind the scenes", read on.
in a nutshell, it comes down to that generics are not there at all at runtime. Generics are just for the compiler to check, so that we can conveniently skip our cast when working with collections. arrays, on the other hand, are checked at runtime, too
this means that some code can't instantiate an array of a generic type, like in
- Code: Select all
class Test<T> {
private T[] t; //possible
public Test() {
t = new T[5]; //impossible
}
public Test(T[] t) {
this.t = t; //possible
}
}
for that reason, an ArrayList, or other collection, internally stores Object[]s, not Arrays of the declared types
when an ArrayList<Deck> is serialized, its content (Deck elements in an Object[]) are stored, but the generic information is gone. When it is deserialized as ArrayList<forge.Deck>, the content (forge.Deck, because of readResolve, in an Object[]) is restored. no problem
however, when storing a Deck[] directly, the array runtime class is stored when serializing. readResolve doesn't apply to it, because it only works for instances of Deck, not Deck[]. now we have a Deck[] array and forge.Deck elements, which doesn't work.
i posted this at the sun forums, that's what I got back:
You have a thoroughly predictable disaster on your hands. Find the original developers and their management and make them fix it. Or have them taken out and shot. There is very little you can do about this problem without a massive amount of work. You are going to have to deserialize all the old data using the old non-packaged classes and re-serialize it using the new packaged classes. While you're at it, make sure all the new serializable classes declare a serialVersionUID member so you will reduce the next most predictable problem to manageability.
as shooting you isn't an option^^, i think we'll really need some sort of a "migration tool". not the most beautiful option, but... i'll try to do that, and before we run it, we'll decide for a final location for our to-be-serialized classes