Top Description Constructors Methods
org.springframework.web.servlet.mvc.method.annotation

public Class JsonViewResponseBodyAdvice

extends AbstractMappingJacksonResponseBodyAdvice
Class Inheritance
Imports
com.fasterxml.jackson.annotation.JsonView, org.springframework.core.MethodParameter, org.springframework.http.MediaType, org.springframework.http.converter.HttpMessageConverter, org.springframework.http.converter.json.MappingJacksonValue, org.springframework.http.server.ServerHttpRequest, .ServerHttpResponse, org.springframework.util.Assert

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 org.springframework.http.converter.json.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.

Author
Rossen Stoyanchev
Since
4.1
See Also
com.fasterxml.jackson.annotation.JsonView, com.fasterxml.jackson.databind.ObjectMapper#writerWithView(Class)

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
beforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType, MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response)

Implements abstract org.springframework.web.servlet.mvc.method.annotation.AbstractMappingJacksonResponseBodyAdvice.beforeBodyWriteInternal.

Invoked only if the converter type is MappingJackson2HttpMessageConverter.

public boolean
supports(MethodParameter
the return type
returnType
,
Class<? extends HttpMessageConverter<?>>
the selected converter type
converterType
)

Overrides org.springframework.web.servlet.mvc.method.annotation.AbstractMappingJacksonResponseBodyAdvice.supports.

Implements org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice.supports.

Whether this component supports the given controller method return type and the selected HttpMessageConverter type.

Inherited from org.springframework.web.servlet.mvc.method.annotation.AbstractMappingJacksonResponseBodyAdvice:
beforeBodyWritegetOrCreateContainer

Constructor Detail

JsonViewResponseBodyAdviceback to summary
public JsonViewResponseBodyAdvice()

Method Detail

beforeBodyWriteInternalback to summary
protected void beforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType, MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response)

Implements abstract org.springframework.web.servlet.mvc.method.annotation.AbstractMappingJacksonResponseBodyAdvice.beforeBodyWriteInternal.

Doc from org.springframework.web.servlet.mvc.method.annotation.AbstractMappingJacksonResponseBodyAdvice.beforeBodyWriteInternal.

Invoked only if the converter type is MappingJackson2HttpMessageConverter.

Annotations
@Override
supportsback to summary
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType)

Overrides org.springframework.web.servlet.mvc.method.annotation.AbstractMappingJacksonResponseBodyAdvice.supports.

Implements org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice.supports.

Doc from org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice.supports.

Whether this component supports the given controller method return type and the selected HttpMessageConverter type.

Parameters
returnType:MethodParameter

the return type

converterType:Class<? extends HttpMessageConverter<?>>

the selected converter type

Returns:boolean

true if beforeBodyWrite should be invoked; false otherwise

Annotations
@Override