سؤال

Suppose you have the following structure (simplified):

interface Inter
{
   //...
}

class Impl1 implements Inter, Serializable
{
   private static final long serialVersionUID = ...;
   //...
}

class Impl2 implements Inter, Serializable
{
   private static final long serialVersionUID = ...;
   //...
}

class MyClass implements Serializable {
   private static final long serialVersionUID = ...;
   Inter interInstance; // can be Impl1, Impl2...
}

Later on, you add a new implementation:

class Impl3 implements Inter, Serializable
{
   private static final long serialVersionUID = ...;
   //...
}

...and end up with three classes that MyClass.interInstance can assume.

Should that have any impact in MyClass objects that are already serialized?

I'm asking this because users (Android app) have been complaining about not being able to open some Serialized objects after an update in which the changes mimic the example above (i.e. I only added a new serializable implementation of the interface).

هل كانت مفيدة؟

المحلول

Should that have any impact in MyClass objects that are already serialized?

I'm little confused from your question but if objects were serialized as Impl1 or Impl2 and you're trying to deserialize as Impl3 - this won't work. So conclusion is when you'll serialize object as Impl1, it has to be deserialised as Impl1.

By the way, especially in Android - officially supported and also recommended way how to "serialize" any kind of object(s) is an usage of Parcelable interface. And why to use it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top