Package org.springframework.web.servlet.mvc.method.annotation

# Interface ResponseBodyAdvice<T>

Type Parameters:
  `T` - the body type

All Known Implementing Classes:
  `AbstractMappingJacksonResponseBodyAdvice`, `JsonViewResponseBodyAdvice`

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

## Method Summary

Modifier and Type
Method
Description
`T`
`beforeBodyWrite(T body, org.springframework.core.MethodParameter returnType, org.springframework.http.MediaType selectedContentType, Class<? extends org.springframework.http.converter.HttpMessageConverter<?>> selectedConverterType, org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response)`
Invoked after an `HttpMessageConverter` is selected and just before its write method is invoked.
`boolean`
`supports(org.springframework.core.MethodParameter returnType, Class<? extends org.springframework.http.converter.HttpMessageConverter<?>> converterType)`
Whether this component supports the given controller method return type and the selected `HttpMessageConverter` type.

## Method Details

### supports

boolean supports(org.springframework.core.MethodParameter returnType, Class<? extends org.springframework.http.converter.HttpMessageConverter<?>> converterType)
Whether this component supports the given controller method return type and the selected `HttpMessageConverter` type.

Parameters:
  `returnType` - the return type
  `converterType` - the selected converter type
Returns:
  `true` if `beforeBodyWrite(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

@Nullable T beforeBodyWrite(@Nullable T body, org.springframework.core.MethodParameter returnType, org.springframework.http.MediaType selectedContentType, Class<? extends org.springframework.http.converter.HttpMessageConverter<?>> selectedConverterType, org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response)
Invoked after an `HttpMessageConverter` is 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