public static byte[] toBytes(Serializable obj) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(obj);
byte[] data = baos.toByteArray();
return data;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
Recommended Posts