Top Description Constructors Methods
org.springframework.web.servlet.mvc.method.annotation

public abstract Class AbstractMappingJacksonResponseBodyAdvice

extends Object
implements ResponseBodyAdvice<Object>
Class Inheritance
All Implemented Interfaces
org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice
Known Direct Subclasses
org.springframework.web.servlet.mvc.method.annotation.JsonViewResponseBodyAdvice
Imports
org.springframework.core.MethodParameter, org.springframework.http.MediaType, org.springframework.http.converter.HttpMessageConverter, org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter, .MappingJacksonValue, org.springframework.http.server.ServerHttpRequest, .ServerHttpResponse, org.springframework.lang.Nullable

A convenient base class for ResponseBodyAdvice implementations that customize the response before JSON serialization with AbstractJackson2HttpMessageConverter's concrete subclasses.
Authors
Rossen Stoyanchev, Sebastien Deleuze
Since
4.1

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final Object
beforeBodyWrite(Object
the body to be written
body
,
MethodParameter
the return type of the controller method
returnType
,
MediaType
the content type selected through content negotiation
contentType
,
Class<? extends HttpMessageConverter<?>>
the converter type selected to write to the response
converterType
,
ServerHttpRequest
the current request
request
,
ServerHttpResponse
the current response
response
)

Implements org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice.beforeBodyWrite.

Invoked after an HttpMessageConverter 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 is MappingJackson2HttpMessageConverter.

protected MappingJacksonValue
getOrCreateContainer(Object body)

Wrap the body in a MappingJacksonValue value container (for providing additional serialization instructions) or simply cast it if already wrapped.

public boolean
supports(MethodParameter
the return type
returnType
,
Class<? extends HttpMessageConverter<?>>
the selected converter type
converterType
)

Implements org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice.supports.

Whether this component supports the given controller method return type and the selected HttpMessageConverter type.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

AbstractMappingJacksonResponseBodyAdviceback to summary
public AbstractMappingJacksonResponseBodyAdvice()

Method Detail

beforeBodyWriteback to summary
public final Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType contentType, Class<? extends HttpMessageConverter<?>> converterType, ServerHttpRequest request, ServerHttpResponse response)

Implements org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice.beforeBodyWrite.

Doc from org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice.beforeBodyWrite.

Invoked after an HttpMessageConverter is selected and just before its write method is invoked.

Parameters
body:Object

the body to be written

returnType:MethodParameter

the return type of the controller method

contentType:MediaType

the content type selected through content negotiation

converterType:Class<? extends HttpMessageConverter<?>>

the converter type selected to write to the response

request:ServerHttpRequest

the current request

response:ServerHttpResponse

the current response

Returns:Object

the body that was passed in or a modified (possibly new) instance

Annotations
@Override
@Nullable
beforeBodyWriteInternalback to summary
protected abstract void beforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType, MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response)

Invoked only if the converter type is MappingJackson2HttpMessageConverter.

getOrCreateContainerback to summary
protected MappingJacksonValue getOrCreateContainer(Object body)

Wrap the body in a MappingJacksonValue value container (for providing additional serialization instructions) or simply cast it if already wrapped.

supportsback to summary
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType)

Implements org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice.supports.

Doc from org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice.supports.

Whether this component supports the given controller method return type and the selected HttpMessageConverter type.

Parameters
returnType:MethodParameter

the return type

converterType:Class<? extends HttpMessageConverter<?>>

the selected converter type

Returns:boolean

true if beforeBodyWrite should be invoked; false otherwise

Annotations
@Override