Reputation: 775
I'm trying to pass a serialized object between applications using a Bundle, where in one app the object is in Java whereas in the other app the same object is in Kotlin.
Passing an object -
Bundle bundle = new Bundle();
bundle.putSerializable(Constants.KEY_USER_PROFILE, getUserProfile());
For Fetching an Object -
Profile profile = (Profile) bundle.getSerializable(Constants.KEY_USER_PROFILE);
In second case profile class is in kotlin language whereas in first it is in java
I'm getting following exception while passing an object
java.lang.RuntimeException: Unable to start activity ComponentInfo{MainActivity}: java.lang.RuntimeException: Parcelable encountered IOException reading a Serializable object (name = base.model.user.Profile)
Caused by: java.lang.RuntimeException: Parcelable encountered IOException reading a Serializable object (name = base.model.user.Profile)
Caused by: java.io.InvalidClassException: base.model.user.Profile; local class incompatible: stream classdesc serialVersionUID = 7285398503547917474, local class serialVersionUID = -1011142074531890510
Upvotes: 0
Views: 224
Reputation: 2600
This is because the serialVersionUID is different in both the cases, It should be the same in serialized and deserialized class for serialization to work. Put this line in both of your classes
public static final long serialVersionUID = 42L;
Upvotes: 1