code: public static byte[] toByteArray(Serializable obj) {
          byte[] bytes = null;
          ObjectOutputStream oos = null;
          ByteArrayOutputStream baos = null;
          try {
              baos = new ByteArrayOutputStream();
              oos = new ObjectOutputStream(baos);
              oos.writeObject(obj);
              oos.flush();
          } catch (Exception e) {
              throw new RuntimeException(e);
          } finally {
              if (oos != null) {
                  try {
                      oos.close();
                      bytes = baos.toByteArray();
                  } catch (IOException e) {
                      throw new RuntimeException(e);
                  }
              }
          }
          return bytes;
      }
docs: 将对象序列化为byte[]
  
  @param obj
  @return