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>
public class JsonViewResponseBodyAdvice extends AbstractMappingJacksonResponseBodyAdvice
AResponseBodyAdviceimplementation that adds support for Jackson's@JsonViewannotation declared on a Spring MVC@RequestMappingor@ExceptionHandlermethod.The serialization view specified in the annotation will be passed in to the
MappingJackson2HttpMessageConverterwhich will then use it to serialize the response body.Note that despite
@JsonViewallowing 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:
JsonView,ObjectMapper.writerWithView(Class)
Constructor Summary
Constructors Constructor Description JsonViewResponseBodyAdvice()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidbeforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType, MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response)Invoked only if the converter type isMappingJackson2HttpMessageConverter.booleansupports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType)Whether this component supports the given controller method return type and the selectedHttpMessageConvertertype.Methods inherited from class org.springframework.web.servlet.mvc.method.annotation.AbstractMappingJacksonResponseBodyAdvice
beforeBodyWrite, getOrCreateContainer
Constructor Detail
JsonViewResponseBodyAdvice
public JsonViewResponseBodyAdvice()
Method Detail
supports
public 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 interfaceResponseBodyAdvice<Object>- Overrides:
supportsin classAbstractMappingJacksonResponseBodyAdvice- Parameters:
returnType- the return typeconverterType- the selected converter type- Returns:
trueifResponseBodyAdvice.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;falseotherwise
beforeBodyWriteInternal
protected 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 classAbstractMappingJacksonResponseBodyAdvice