Use ResponseBodyAdvice to modify the response before it was written to the HTTP response. In the beforeBodyWrite(...) method, you have access to the current ServerHttpRequest , which you can read with the value of fields . Your body advice will look like this:
@ControllerAdvice public class MyResponseBodyAdvisor implements ResponseBodyAdvice<UserResource> { @Override public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) { return returnType.getParameterType().equals(UserResource.class); } @Override public UserResource beforeBodyWrite(UserResource body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) { String fields = ((ServletServerHttpRequest) request).getServletRequest().getParameter("fields");
source share