public static String objectToBase64(Object obj) throws Exception{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ObjectOutputStream object = new ObjectOutputStream(outputStream);
object.writeObject(obj);
byte[] buffer = outputStream.toByteArray();
return Base64.encodeToString(buffer);
}
public static Object base64ToObj(String tmp) throws Exception
{
byte[] buffer2 = Base64.decode(tmp);
ByteArrayInputStream inputStream =new ByteArrayInputStream(buffer2);
ObjectInputStream object= new ObjectInputStream(inputStream);
return object.readObject();
}
实例对象的类需要实现serviable 接口