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