Class AbstractMappingJacksonResponseBodyAdvice
- java.lang.Object
- org.springframework.web.servlet.mvc.method.annotation.AbstractMappingJacksonResponseBodyAdvice
- All Implemented Interfaces:
ResponseBodyAdvice<Object>
- Direct Known Subclasses:
AbstractJsonpResponseBodyAdvice
,JsonViewResponseBodyAdvice
public abstract class AbstractMappingJacksonResponseBodyAdvice extends Object implements ResponseBodyAdvice<Object>
A convenient base class forResponseBodyAdvice
implementations that customize the response before JSON serialization withAbstractJackson2HttpMessageConverter
's concrete subclasses.- Since:
- 4.1
- Author:
- Rossen Stoyanchev, Sebastien Deleuze
Constructor Summary
Constructors Constructor Description AbstractMappingJacksonResponseBodyAdvice()
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Object
beforeBodyWrite(Object body, MethodParameter returnType, MediaType contentType, Class<? extends HttpMessageConverter<?>> converterType, ServerHttpRequest request, ServerHttpResponse response)
Invoked after anHttpMessageConverter
is selected and just before its write method is invoked.protected abstract void
beforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType, MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response)
Invoked only if the converter type isMappingJackson2HttpMessageConverter
.protected MappingJacksonValue
getOrCreateContainer(Object body)
Wrap the body in aMappingJacksonValue
value container (for providing additional serialization instructions) or simply cast it if already wrapped.boolean
supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType)
Whether this component supports the given controller method return type and the selectedHttpMessageConverter
type.
Constructor Detail
AbstractMappingJacksonResponseBodyAdvice
public AbstractMappingJacksonResponseBodyAdvice()
Method Detail
supports
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType)
Description copied from interface:ResponseBodyAdvice
Whether this component supports the given controller method return type and the selectedHttpMessageConverter
type.- Specified by:
supports
in interfaceResponseBodyAdvice<Object>
- Parameters:
returnType
- the return typeconverterType
- the selected converter type- Returns:
true
ifResponseBodyAdvice.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
public final Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType contentType, Class<? extends HttpMessageConverter<?>> converterType, ServerHttpRequest request, ServerHttpResponse response)
Description copied from interface:ResponseBodyAdvice
Invoked after anHttpMessageConverter
is selected and just before its write method is invoked.- Specified by:
beforeBodyWrite
in interfaceResponseBodyAdvice<Object>
- Parameters:
body
- the body to be writtenreturnType
- the return type of the controller methodcontentType
- the content type selected through content negotiationconverterType
- 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
getOrCreateContainer
protected MappingJacksonValue getOrCreateContainer(Object body)
Wrap the body in aMappingJacksonValue
value container (for providing additional serialization instructions) or simply cast it if already wrapped.
beforeBodyWriteInternal
protected abstract void beforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType, MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response)
Invoked only if the converter type isMappingJackson2HttpMessageConverter
.