在 spring 中调用 jackson 之前获取 http post 请求 body

get the http post request body before jackson invocation in spring

我想知道有没有办法在任何 Jackson 参与 spring 之前获得 HttpServletRequest body。我用 @JsonDeserializer 和 spring HandlerInterceptorAdapter 以及 HttpRequestWrapper 试过了,但现在运气不好。如果有人知道请建议我一种方法,谢谢。

您可以在应用程序中添加自定义 Filter(已解释 here)并覆盖 doFilter 方法。例如:

public void doFilter(
      ServletRequest request, 
      ServletResponse response,
      FilterChain chain){
       ....
}

这将为您提供 request 对象,您可以从中获取有效载荷。