The Dark Side Of A Developer

Wednesday, May 25, 2005

JAVA KNOWLEDGE ! [ ArrayList deserialization problem]

Java Forums - ArrayList deserialization problem: "Re: ArrayList deserialization problem
Author: sylviae May 25, 2005 12:47 AM (reply 3 of 4)


You're actually corrupting the serialized form by converting from a stream of bytes into a String, and then back again.

As a general rule, you cannot convert a random array of bytes into a String and back again and expect to have what you started with. In your particular case, it's altered the serialization identifier for the ArrayList class, but there's no predicting what it might do.

Use toByteArray() to get the serialized form as an array of bytes, and then construct your input stream from that and it will work.

BTW, you really should include a call to ous.flush() before you obtain the byte array.

Sylvia."

0 Comments:

Post a Comment

<< Home