I want to send an object using Messageapi from a smart watch to smart phone. Since messageapi needs byte array to send messages, I want to convert my object to a byte array. I used apache utils to serialize and deserialize. I am getting the following error while serializing:
org.apache.commons.lang3.SerializationException: java.io.NotSerializableException: android.os.Bundle
at org.apache.commons.lang3.SerializationUtils.serialize(SerializationUtils.java:156)
at org.apache.commons.lang3.SerializationUtils.serialize(SerializationUtils.java:178)
My object has two variables - one string and one android bundle.
Following is the code implementation:
To Serialize:
byte[] data = SerializationUtils.serialize(myObject);
To deserialize:
MyObject myObject = (MyObject) SerializationUtils.deserialize(byte[] data)
What is the best method to serialize an object containing android bundle?
MyObject class is as below:
public class MyObject implements Serializable {
private String type;
private Bundle data;
public String getType() {
return type;
}
public void setType(String value) {
type = value;
}
public Bundle getData() {
return data;
}
public void setData(Bundle value) {
data = value;
}
}
PS: I have tried Parcelable to serialize objects containing android bundle and it works in devices of same OS versions. But it doesn't work when the two devices involved have different versions of OS(for example, sending a message from API level 23 device to an API level 15 device using wifip2p). So I am looking for a method which works all the time.