Interface ResponseBodyAdvice<T>
- Type Parameters:
- T- the body type
- All Known Implementing Classes:
- AbstractMappingJacksonResponseBodyAdvice, JsonViewResponseBodyAdvice, KotlinResponseBodyAdvice
public interface ResponseBodyAdvice<T>
Allows customizing the response after the execution of an 
@ResponseBody
or a ResponseEntity controller method but before the body is written
with an HttpMessageConverter.
Implementations may be registered directly with
RequestMappingHandlerAdapter and ExceptionHandlerExceptionResolver
or more likely annotated with @ControllerAdvice in which case they
will be auto-detected by both.
- Since:
- 4.1
- Author:
- Rossen Stoyanchev, Sebastien Deleuze
- 
Method SummaryModifier and TypeMethodDescriptionbeforeBodyWrite(@Nullable T body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) Invoked after anHttpMessageConverteris selected and just before its write method is invoked.determineWriteHints(@Nullable T body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType) Invoked to determine write hints if the converter is aSmartHttpMessageConverter.booleansupports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) Whether this component supports the given controller method return type and the selectedHttpMessageConvertertype.
- 
Method Details- 
supportsboolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) Whether this component supports the given controller method return type and the selectedHttpMessageConvertertype.- Parameters:
- returnType- the return type
- converterType- the selected converter type
- Returns:
- trueif- beforeBodyWrite(T, MethodParameter, MediaType, Class, ServerHttpRequest, ServerHttpResponse)should be invoked;- falseotherwise
 
- 
beforeBodyWrite@Nullable T beforeBodyWrite(@Nullable T body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) Invoked after anHttpMessageConverteris selected and just before its write method is invoked.- Parameters:
- body- the body to be written
- returnType- the return type of the controller method
- selectedContentType- the content type selected through content negotiation
- selectedConverterType- the converter type selected to write to the response
- request- the current request
- response- the current response
- Returns:
- the body that was passed in or a modified (possibly new) instance
 
- 
determineWriteHintsdefault @Nullable Map<String,Object> determineWriteHints(@Nullable T body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType) Invoked to determine write hints if the converter is aSmartHttpMessageConverter.- Parameters:
- body- the body to be written
- returnType- the return type of the controller method
- selectedContentType- the content type selected through content negotiation
- selectedConverterType- the converter type selected to write to the response
- Returns:
- the hints determined otherwise null
- Since:
- 7.0
 
 
-