It is illegal to call this method if the current request is not in asynchron

问题

在使用切面+自定义注解实现日志记录时报的错

原因

proceedingJoinPoint.getArgs()返回的数组中携带有Request或者Response对象,导致序列化异常

解决

过滤掉之后再转换

        //获取传参信息
        Object[] args = proceedingJoinPoint.getArgs();
        //过滤无法序列化
        Stream<?> stream = ArrayUtils.isEmpty(args) ? Stream.empty() : Arrays.stream(args);
        List<Object> logArgs = stream
                .filter(arg -> (!(arg instanceof HttpServletRequest) && !(arg instanceof HttpServletResponse)))
                .collect(Collectors.toList());
        //过滤后序列化无异常
        String requestParam = JSON.toJSONString(logArgs);