spring-framework / org.springframework.web.servlet.mvc.method.annotation / JsonViewResponseBodyAdvice

JsonViewResponseBodyAdvice

open class JsonViewResponseBodyAdvice : AbstractMappingJacksonResponseBodyAdvice

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.JsonViewcom.fasterxml.jackson.databind.ObjectMapper#writerWithView(Class)

Constructors

<init>

JsonViewResponseBodyAdvice()

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.

Functions

supports

open fun supports(returnType: MethodParameter, converterType: Class<out HttpMessageConverter<*>>): Boolean