Class AbstractMappingJacksonResponseBodyAdvice
java.lang.Object
org.springframework.web.servlet.mvc.method.annotation.AbstractMappingJacksonResponseBodyAdvice
- All Implemented Interfaces:
- ResponseBodyAdvice<Object>
- Direct Known Subclasses:
- JsonViewResponseBodyAdvice
public abstract class AbstractMappingJacksonResponseBodyAdvice
extends Object
implements ResponseBodyAdvice<Object>
A convenient base class for 
ResponseBodyAdvice implementations
that customize the response before JSON serialization with
AbstractJacksonHttpMessageConverter's and
AbstractJackson2HttpMessageConverter's concrete subclasses.- Since:
- 4.1
- Author:
- Rossen Stoyanchev, Sebastien Deleuze
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionbeforeBodyWrite(@Nullable Object body, MethodParameter returnType, MediaType contentType, Class<? extends HttpMessageConverter<?>> converterType, ServerHttpRequest request, ServerHttpResponse response) Invoked after anHttpMessageConverteris selected and just before its write method is invoked.protected abstract voidbeforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType, MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response) Invoked only if the converter type isMappingJackson2HttpMessageConverter.protected MappingJacksonValuegetOrCreateContainer(Object body) Wrap the body in aMappingJacksonValuevalue container (for providing additional serialization instructions) or simply cast it if already wrapped.booleansupports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) Whether this component supports the given controller method return type and the selectedHttpMessageConvertertype.Methods inherited from class Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ResponseBodyAdvicedetermineWriteHints
- 
Constructor Details- 
AbstractMappingJacksonResponseBodyAdvicepublic AbstractMappingJacksonResponseBodyAdvice()
 
- 
- 
Method Details- 
supportspublic 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 interface- ResponseBodyAdvice<Object>
- Parameters:
- returnType- the return type
- converterType- the selected converter type
- Returns:
- trueif- ResponseBodyAdvice.beforeBodyWrite(T, MethodParameter, MediaType, Class, ServerHttpRequest, ServerHttpResponse)should be invoked;- falseotherwise
 
- 
beforeBodyWritepublic final @Nullable Object beforeBodyWrite(@Nullable Object body, MethodParameter returnType, MediaType contentType, Class<? extends HttpMessageConverter<?>> converterType, ServerHttpRequest request, ServerHttpResponse response) Description copied from interface:ResponseBodyAdviceInvoked after anHttpMessageConverteris selected and just before its write method is invoked.- Specified by:
- beforeBodyWritein interface- ResponseBodyAdvice<Object>
- Parameters:
- body- the body to be written
- returnType- the return type of the controller method
- contentType- the content type selected through content negotiation
- converterType- 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
 
- 
getOrCreateContainerWrap the body in aMappingJacksonValuevalue container (for providing additional serialization instructions) or simply cast it if already wrapped.
- 
beforeBodyWriteInternalprotected abstract void beforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType, MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response) Invoked only if the converter type isMappingJackson2HttpMessageConverter.
 
-