I\'m trying to serialize and deserialize an array list with a object inside:
HairBirt param = new HairBirt();
param.setName(\"name\");
param.setValue(2.3f);
Don't use ByteArrayOutputStream.toString()
- instead, use toByteArray()
and base64-encode that binary data to convert it into a string without losing information.
I strongly suspect that's the main problem - that you were losing the data after serialization. You should probably also close or at least flush the ObjectOutputStream
. I don't know offhand whether that actually does anything in this case, but it would seem to be a good idea.
I don't believe there's any base64 support directly in Java (in a public class, anyway) but there are various 3rd party libraries you can use, such as the one in the Apache Commons Codec library.
Have you tried overriding this behavior by declaring your own serialVersionUID in your custom class?
Do you have a specific reason for doing the extra step of serializing through a string? Normally you would just deserialize through an ObjectOutputStream.