public static byte[] serialize(Serializable obj) { ByteArrayOutputStream baos = new ByteArrayOutputStream(512); serialize(obj, baos); return baos.toByteArray();
public static void serialize(Serializable obj, OutputStream outputStream) { if (outputStream == null) { throw new IllegalArgumentException("The OutputStream must not be null"); } ObjectOutputStream out = null; try {  out = new ObjectOutputStream(outputStream); out.writeObject(obj);  } catch (IOException ex) { throw new SerializationException(ex); } finally { try { if (out != null) { out.close(); } } catch (IOException ex) {  } }
    public static byte[] serialize(Serializable obj) {        ByteArrayOutputStream baos = new ByteArrayOutputStream(512);        serialize(obj, baos);        return baos.toByteArray();    }