/**
   * Converts a proxy object to an object that is writable to an object stream. This method is
   * called by <code>writeReplace()</code> in a proxy class.
   *
   * @since 3.4
   */
  public static SerializedProxy makeSerializedProxy(Object proxy)
      throws java.io.InvalidClassException {
    Class clazz = proxy.getClass();

    MethodHandler methodHandler = null;
    if (proxy instanceof ProxyObject) methodHandler = ((ProxyObject) proxy).getHandler();
    else if (proxy instanceof Proxy) methodHandler = ProxyFactory.getHandler((Proxy) proxy);

    return new SerializedProxy(clazz, ProxyFactory.getFilterSignature(clazz), methodHandler);
  }