I have a java library, I would like to save an instance of a java object to a text file. I have tried to use all java libraries for serialization and deserialization to xml: http://karussell.wordpress.com/2009/09/03/xml-serializers-for-java/ but deserializing does not work. I have posted a question here: http://stackoverflow.com/questions/6139702/deserializing-xml-file-from-xstream but It seems that I could not get a solution for that.
I also have tried to serialize to json but deserialize from json does not work.
So, I would like to know apart of serializing to xml and json, is there any other way to do serialization and deserialization from a java object (cannot modify to add tags: @XmlRootElement(name="customer")) to text file?
Thanks in advance!
The easiest way is probably to use the native Java serialization. It will generate a binary representation of the object, but you can encode the generated byte array with Base64 to transform it to text:
Note that the object, and every object it references (recursively) must implement
java.io.Serializablefor this to work.