python-javaobj
python-javaobj copied to clipboard
if serialized by encoding toString ISO-8859-1, how to unserialized
public static String serialize(Object obj) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream; objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.writeObject(obj); //String string = byteArrayOutputStream.toString(); String string = byteArrayOutputStream.toString("ISO-8859-1"); objectOutputStream.close(); byteArrayOutputStream.close(); return string; }
If I understand correctly, you want to transmit the serialized object as a String
.
The ISO-8859-1 encoding should indeed ensure to have the equivalent of the underlying bytes without conversion nor error.
Note that internally, the String will have its "modified UTF-8" representation of the content: it is a Java String.
If you can, it would be preferable to use the byte array returned by byteArrayOutputStream.toByteArray()
, as you won't have to handle encoding.
If you need the result to be a String, I recommend you to use a format that is not sensitive to the encoding, like Base64
thanks very much, i'll hava a try with base64