类 JsonViewResponseBodyAdvice
- java.lang.Object
- org.springframework.web.servlet.mvc.method.annotation.AbstractMappingJacksonResponseBodyAdvice
- org.springframework.web.servlet.mvc.method.annotation.JsonViewResponseBodyAdvice
- 所有已实现的接口:
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.- 从以下版本开始:
- 4.1
- 作者:
- Rossen Stoyanchev
- 另请参阅:
JsonView,ObjectMapper.writerWithView(Class)
构造器概要
构造器 构造器 说明 JsonViewResponseBodyAdvice()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 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.从类继承的方法 org.springframework.web.servlet.mvc.method.annotation.AbstractMappingJacksonResponseBodyAdvice
beforeBodyWrite, getOrCreateContainer
构造器详细资料
JsonViewResponseBodyAdvice
public JsonViewResponseBodyAdvice()
方法详细资料
supports
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType)
从接口复制的说明:ResponseBodyAdviceWhether this component supports the given controller method return type and the selectedHttpMessageConvertertype.- 指定者:
supports在接口中ResponseBodyAdvice<Object>- 覆盖:
supports在类中AbstractMappingJacksonResponseBodyAdvice- 参数:
returnType- the return typeconverterType- the selected converter type- 返回:
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)
Invoked only if the converter type isMappingJackson2HttpMessageConverter.