Deserializing an ArrayList string
My goal is to create a function that creates a string from an ArrayList, which I can easily do in many ways. Then the caller needs to reconstruct that ArrayList, which is where I'm having trouble.
Does there exist a function to do that -- to go from the serialized ArrayList string to the ArrayList?
The key here is that my function must return a string, not a stream or anything else, and I'm hoping to not create any new functions to reconstruct it -- just call existing ones.
# 1
Why do you have to put it in a string? Serialised objects are binary. Strings are not suitable places to store binary data. The round-trip from binary->String->binary is not idempotent.
You should either store your serialised object in some non-string way, or else you should encode your binary data using a character encoding such as UUEncode or base64
# 2
I'm organizing data from a database query using my ArrayList. However, the code I'm working with only gives me the option of passing my data using a string.
I know I could use a character delimited string to organize it, then easily split that after passing it, but am looking for something that relies less on the coder in case we change the data we query, for example, add a value to it.
So if there is a better way to do this, I'm open for that as well.
# 3
Well, if you absolutely must do this, then you need to perform some kind of binary-to-text conversion like the ones I mentioned earlier. Java strings are not suitable for the storage of binary data (unlike C/C++ strings which are)