Class KotlinResponseBodyAdvice

java.lang.Object
org.springframework.web.servlet.mvc.method.annotation.KotlinResponseBodyAdvice
All Implemented Interfaces:
ResponseBodyAdvice<Object>

public class KotlinResponseBodyAdvice extends Object implements 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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    beforeBodyWrite(@Nullable Object 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.
    determineWriteHints(@Nullable Object body, org.springframework.core.MethodParameter returnType, org.springframework.http.MediaType selectedContentType, Class<? extends org.springframework.http.converter.HttpMessageConverter<?>> selectedConverterType)
    Invoked to determine write hints if the converter is a SmartHttpMessageConverter.
    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.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • KotlinResponseBodyAdvice

      public KotlinResponseBodyAdvice()
  • Method Details

    • supports

      public boolean supports(org.springframework.core.MethodParameter returnType, Class<? extends org.springframework.http.converter.HttpMessageConverter<?>> converterType)
      Description copied from interface: ResponseBodyAdvice
      Whether this component supports the given controller method return type and the selected HttpMessageConverter type.
      Specified by:
      supports in interface ResponseBodyAdvice<Object>
      Parameters:
      returnType - the return type
      converterType - the selected converter type
      Returns:
      true if ResponseBodyAdvice.beforeBodyWrite(T, MethodParameter, MediaType, Class, ServerHttpRequest, ServerHttpResponse) should be invoked; false otherwise
    • beforeBodyWrite

      public @Nullable Object beforeBodyWrite(@Nullable Object 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)
      Description copied from interface: ResponseBodyAdvice
      Invoked after an HttpMessageConverter is selected and just before its write method is invoked.
      Specified by:
      beforeBodyWrite in interface ResponseBodyAdvice<Object>
      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
    • determineWriteHints

      public @Nullable Map<String,Object> determineWriteHints(@Nullable Object body, org.springframework.core.MethodParameter returnType, org.springframework.http.MediaType selectedContentType, Class<? extends org.springframework.http.converter.HttpMessageConverter<?>> selectedConverterType)
      Description copied from interface: ResponseBodyAdvice
      Invoked to determine write hints if the converter is a SmartHttpMessageConverter.
      Specified by:
      determineWriteHints in interface ResponseBodyAdvice<Object>
      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