user1300214
user1300214

Reputation:

class serialisation between desktop and Android applications

I have a desktop application (not Android) which allows me to instantiate a class, alter it's internal state, and serialize it to a file (using the standard Java serialisation mechanism). This file I then copy into the resources of my separate Android app. I wish to deserialise this file into the same class structure which I have in my Android app.

However, there are slight differences in the data members between the desktop and Android classes since, for example, I cannot use BufferedImage in Android and instead have to use Bitmap.

Clearly the system is not going to like this, so since it makes no difference to me I made these particular data members transient. After serialising again on the desktop, the file still does not deserialise on Android. I get the ClassNotFoundException error on executing

myclass = (MyClass)ois.readObject();

Does anyone know if I can achieve my goal using Externalizable by writing my own serialisation functions, or will I have to write totally separate serialisation (without Serializable/Externalizable)

Upvotes: 0

Views: 127

Answers (1)

user1300214
user1300214

Reputation:

To solve this problem you need to implement Externalizable and implement your own serialization functions. This enables you to serialize and deserialize the same data within different classes.

However, the ClassNotFoundException was a result of incorrect serialization/deserialization of the enum type.

Upvotes: 0

Related Questions