Class KotlinResponseBodyAdvice
java.lang.Object
org.springframework.web.servlet.mvc.method.annotation.KotlinResponseBodyAdvice
- All Implemented Interfaces:
ResponseBodyAdvice<Object>
A
ResponseBodyAdvice implementation that adds support for resolving
Kotlin KType from the return type and providing it as a hint with a
"kotlin.reflect.KType" key.- Since:
- 7.0
- Author:
- Sebastien Deleuze
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbeforeBodyWrite(@Nullable Object 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 Object 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.
-
Constructor Details
-
KotlinResponseBodyAdvice
public KotlinResponseBodyAdvice()
-
-
Method Details
-
supports
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) Description copied from interface:ResponseBodyAdviceWhether this component supports the given controller method return type and the selectedHttpMessageConvertertype.- Specified by:
supportsin interfaceResponseBodyAdvice<Object>- Parameters:
returnType- the return typeconverterType- the selected converter type- Returns:
trueifResponseBodyAdvice.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;falseotherwise
-
beforeBodyWrite
public @Nullable Object beforeBodyWrite(@Nullable Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) Description copied from interface:ResponseBodyAdviceInvoked after anHttpMessageConverteris selected and just before its write method is invoked.- Specified by:
beforeBodyWritein interfaceResponseBodyAdvice<Object>- 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
-
determineWriteHints
public @Nullable Map<String,Object> determineWriteHints(@Nullable Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType) Description copied from interface:ResponseBodyAdviceInvoked to determine write hints if the converter is aSmartHttpMessageConverter.- Specified by:
determineWriteHintsin interfaceResponseBodyAdvice<Object>- 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 response- Returns:
- the hints determined otherwise
null
-