org.springframework.web.servlet.mvc.method.annotation

Class JsonViewResponseBodyAdvice

  • All Implemented Interfaces:
    ResponseBodyAdvice<java.lang.Object>


    public class JsonViewResponseBodyAdvice
    extends 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 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.

    Since:
    4.1
    Author:
    Rossen Stoyanchev
    See Also:
    JsonView, ObjectMapper.writerWithView(Class)