public static byte[] toBytes(Serializable serializable, Object... args) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream(512);
    final Object[] stack = SerializationProxy.swapExtraArguments(args);
    try (ObjectOutput oos = new ObjectOutputStream(bos)) {
      oos.writeObject(serializable);
      oos.flush();
      return bos.toByteArray();
    } catch (IOException xany) {
      throw ProxyException.convert(xany);
    } finally {
      SerializationProxy.swapExtraArguments(stack);
    }
  }
Converts a serializable object to an array of bytes.
@param serializable the object to serialize
@param args the proxy arguments
@return the array of bytes
@throws ProxyException on any underlying error
standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/properties/SerializationProxy.java