Showing posts with label ResponseBodyAdvice. Show all posts
Showing posts with label ResponseBodyAdvice. Show all posts

Sunday, October 16, 2016

[JAVA,SPRING] Intercept and modify @ResponseBody before sending it back

So I got this idea to have a single common place to modify all my ResponseBody before sending it back to the caller. Initially I thought I can use Spring's HandlerInterceptor but I found out that ResponseBody can only be read once. Once it is read by HandlerInterceptor class, the ResponseBody will be gone. After much googling, I found out there are few solution to this. First is to implement a filter class. Another way is using ControllerAdvice classes which I will share below.