Interface ResponseBodyAdvice<T>
- All Known Implementing Classes:
AbstractJsonpResponseBodyAdvice
,AbstractMappingJacksonResponseBodyAdvice
,JsonViewResponseBodyAdvice
public interface ResponseBodyAdvice<T>
Allows customizing the response after the execution of an@ResponseBody
or aResponseEntity
controller method but before the body is written with anHttpMessageConverter
.Implementations may be registered directly with
RequestMappingHandlerAdapter
andExceptionHandlerExceptionResolver
or more likely annotated with@ControllerAdvice
in which case they will be auto-detected by both.- Since:
- 4.1
- Author:
- Rossen Stoyanchev
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description T
beforeBodyWrite(T body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response)
Invoked after anHttpMessageConverter
is selected and just before its write method is invoked.boolean
supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType)
Whether this component supports the given controller method return type and the selectedHttpMessageConverter
type.
Method Detail
supports
boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType)
Whether this component supports the given controller method return type and the selectedHttpMessageConverter
type.- Parameters:
returnType
- the return typeconverterType
- the selected converter type- Returns:
true
ifbeforeBodyWrite(T, org.springframework.core.MethodParameter, org.springframework.http.MediaType, java.lang.Class<? extends org.springframework.http.converter.HttpMessageConverter<?>>, org.springframework.http.server.ServerHttpRequest, org.springframework.http.server.ServerHttpResponse)
should be invoked;false
otherwise
beforeBodyWrite
T beforeBodyWrite(T body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response)
Invoked after anHttpMessageConverter
is selected and just before its write method is invoked.- Parameters:
body
- the body to be writtenreturnType
- the return type of the controller methodselectedContentType
- the content type selected through content negotiationselectedConverterType
- the converter type selected to write to the responserequest
- the current requestresponse
- the current response- Returns:
- the body that was passed in or a modified (possibly new) instance