Muralidhar Yaragalla
Muralidhar Yaragalla

Reputation: 427

Serialization in android?

Hi I am serializing an object using different VM (Oracle hotspot,jse) and deserializing it with android VM(dalvik). will there be any problem?

Upvotes: 0

Views: 582

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006539

Assuming that by "serialization" you mean Serializable, then yes. Serialization is not guaranteed to be the same across distinct VMs. Please use something else (e.g., XML, JSON).

UPDATE

Your first comment is so flawed that I cannot fit my response in 500 characters.

ofcourse yes. without implementing Serializable we cannot serialize

Talented programmers can. Talented programmers can serialize data to XML, JSON, Protocol Buffers, Thrift, ASN.l, YAML, and any number of other formats.

what actually i am doing is i am writing an object on to the network using ObjectOutputStream(oracle hotspot) and reading that object on the android using ObjectInputStream

Talented programmers use platform-independent serialization approaches, such as any of the ones I listed above. That is because talented programmers realize that, in the future, there may be need to have clients or servers that are not based in Java.

So you mean to say as of now this is fine but in the future it is not guaranteed.

No. I wrote:

Serialization is not guaranteed to be the same across distinct VMs.

An object serialized using one VM (e.g., Oracle) should be able to be de-serialized using that VM. There is no guarantee that an object serialized with one VM can be de-serialized using another VM. In fact, developers have gotten in trouble trying to do precisely what you are trying to do. This is another example of why talented programmers use platform-independent serialization structures.

Upvotes: 2

Related Questions