public static String serializeCar(Car car) { ObjectOutputStream oos = null; Base64OutputStream b64 = null; try { ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream(); oos = new ObjectOutputStream(byteArrayOut); oos.writeObject(car); oos.flush(); ByteArrayOutputStream out = new ByteArrayOutputStream(); b64 = new Base64OutputStream(out, Base64.DEFAULT); b64.write(byteArrayOut.toByteArray()); b64.flush(); b64.close(); out.flush(); out.close(); String result = new String(out.toByteArray()); return result; } catch (IOException e) { logger.warn(e.getMessage(), e); } finally { if (oos != null) try { b64.close(); oos.close(); } catch (IOException e) { logger.warn(e.getMessage(), e); } } return null; }