Package org.springframework.web.servlet.mvc.method.annotation

# 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 `AbstractJackson2HttpMessageConverter`'s concrete subclasses.

Since:
  4.1
Author:
  Rossen Stoyanchev, Sebastien Deleuze

## Constructor Summary

Constructors
Constructor
Description
`AbstractMappingJacksonResponseBodyAdvice()`

## Method Summary

Modifier and Type
Method
Description
`final Object`
`beforeBodyWrite(Object body, org.springframework.core.MethodParameter returnType, org.springframework.http.MediaType contentType, Class<? extends org.springframework.http.converter.HttpMessageConverter<?>> converterType, 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.
`protected abstract void`
`beforeBodyWriteInternal(org.springframework.http.converter.json.MappingJacksonValue bodyContainer, org.springframework.http.MediaType contentType, org.springframework.core.MethodParameter returnType, org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response)`
Invoked only if the converter type is `MappingJackson2HttpMessageConverter`.
`protected org.springframework.http.converter.json.MappingJacksonValue`
`getOrCreateContainer(Object body)`
Wrap the body in a `MappingJacksonValue` value container (for providing additional serialization instructions) or simply cast it if already wrapped.
`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 java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### AbstractMappingJacksonResponseBodyAdvice

public AbstractMappingJacksonResponseBodyAdvice()

## 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, 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

@Nullable public final Object beforeBodyWrite(@Nullable Object body, org.springframework.core.MethodParameter returnType, org.springframework.http.MediaType contentType, Class<? extends org.springframework.http.converter.HttpMessageConverter<?>> converterType, 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
  `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

### getOrCreateContainer

protected org.springframework.http.converter.json.MappingJacksonValue getOrCreateContainer(Object body)
Wrap the body in a `MappingJacksonValue` value container (for providing additional serialization instructions) or simply cast it if already wrapped.

### beforeBodyWriteInternal

protected abstract void beforeBodyWriteInternal(org.springframework.http.converter.json.MappingJacksonValue bodyContainer, org.springframework.http.MediaType contentType, org.springframework.core.MethodParameter returnType, org.springframework.http.server.ServerHttpRequest request, org.springframework.http.server.ServerHttpResponse response)
Invoked only if the converter type is `MappingJackson2HttpMessageConverter`.