Getoutputstream() has already been called for this response

java.lang.IllegalStateException: getOutputStream() has already been called for this response
        at org.apache.catalina.connector.Response.getWriter(Response.java:581)
        at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:227)
        at com.alibaba.fastjson.serializer.ASMSerializer_10_ResponseFacade.write(Unknown Source)
        at com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:333)
        at com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:311)
        at com.alibaba.fastjson.serializer.ObjectArrayCodec.write(ObjectArrayCodec.java:118)
        at com.alibaba.fastjson.serializer.JSONSerializer.write(JSONSerializer.java:285)
        at com.alibaba.fastjson.JSON.toJSONString(JSON.java:740)
        at com.alibaba.fastjson.JSON.toJSONString(JSON.java:678)
        at com.alibaba.fastjson.JSON.toJSONString(JSON.java:643)

Problem scenario: block the print request parameters in the class, and use jsonobject to convert httpservletresponse to a string.

private Object printLog(ProceedingJoinPoint joinPoint) throws Throwable {
   String ipAddress = IpAddressUtil.getIpAddress(request);
   String url = request.getRequestURL().toString();
   String params = JSON.toJSONString(joinPoint.getArgs());
   Object proceed = joinPoint.proceed();
   String result = JSON.toJSONString(proceed);
   log.info("\n-----------------------------------------------------------------------------------------------" +
          "\n<> IP:{} " +
          "\n<> url:{} " +
          "\n<> params:{} " +
          "\n<> result:{}" +
          "\n-----------------------------------------------------------------------------------------------" , ipAddress, url, params, result);
   return proceed;
}

Cause problem: the interface has two parameters, one of which is httpservletresponse

At this time, the interceptor will report an error when printing parameters.
When checking the debug, it is found that there is an error in calling getwriter after getting the object through reflection, which leads to an exception in JSON transformation
Alibaba JSON is getting the object serializer class asmserializer_ 1_ Resposefacade called ResponseFacade.getWriter ()
write javaBean error, fastjson version 1.2.58, class com.sun.proxy .$Proxy128, method : getWriter

Error usage code:

HttpServletResponse response;
JSON.toJSONString (response);
to sum up, jsonobject is unable to serialize httpservletresponse, thus reporting the above exception

Read More: