code: protected static Method getWriteReplace(Class<?> cl, Class<?> param)
      {
          for (; cl != null; cl = cl.getSuperclass()) {
              for (Method method : cl.getDeclaredMethods()) {
                  if (method.getName().equals("writeReplace")
                      && method.getParameterTypes().length == 1
                      && param.equals(method.getParameterTypes()[0]))
                      return method;
              }
          }
  
          return null;
      }
docs: Returns the writeReplace method