Class JsonViewResponseBodyAdvice
java.lang.Object
org.springframework.web.servlet.mvc.method.annotation.AbstractMappingJacksonResponseBodyAdvice
org.springframework.web.servlet.mvc.method.annotation.JsonViewResponseBodyAdvice
- All Implemented Interfaces:
- ResponseBodyAdvice<Object>
A 
ResponseBodyAdvice implementation that adds support for Jackson's
@JsonView annotation declared on a Spring MVC @RequestMapping
or @ExceptionHandler method.
The serialization view specified in the annotation will be passed in to the
MappingJackson2HttpMessageConverter
which will then use it to serialize the response body.
Note that despite @JsonView allowing for more than one class to
be specified, the use for a response body advice is only supported with
exactly one class argument. Consider the use of a composite interface.
- Since:
- 4.1
- Author:
- Rossen Stoyanchev
- See Also:
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidbeforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType, MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response) Invoked only if the converter type isMappingJackson2HttpMessageConverter.determineWriteHints(@Nullable Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType) Invoked to determine write hints if the converter is aSmartHttpMessageConverter.booleansupports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) Whether this component supports the given controller method return type and the selectedHttpMessageConvertertype.Methods inherited from class AbstractMappingJacksonResponseBodyAdvicebeforeBodyWrite, getOrCreateContainer
- 
Constructor Details- 
JsonViewResponseBodyAdvicepublic JsonViewResponseBodyAdvice()
 
- 
- 
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>
- Overrides:
- supportsin class- AbstractMappingJacksonResponseBodyAdvice
- Parameters:
- returnType- the return type
- converterType- the selected converter type
- Returns:
- trueif- ResponseBodyAdvice.beforeBodyWrite(T, MethodParameter, MediaType, Class, ServerHttpRequest, ServerHttpResponse)should be invoked;- falseotherwise
 
- 
beforeBodyWriteInternalprotected void beforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType, MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response) Description copied from class:AbstractMappingJacksonResponseBodyAdviceInvoked only if the converter type isMappingJackson2HttpMessageConverter.- Specified by:
- beforeBodyWriteInternalin class- AbstractMappingJacksonResponseBodyAdvice
 
- 
determineWriteHintspublic @Nullable Map<String,Object> determineWriteHints(@Nullable Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType) Description copied from interface:ResponseBodyAdviceInvoked to determine write hints if the converter is aSmartHttpMessageConverter.- 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
 
 
-