Search in sources :

Example 1 with MappingJacksonInputMessage

use of org.springframework.http.converter.json.MappingJacksonInputMessage in project spring-framework by spring-projects.

the class JsonViewRequestBodyAdvice method beforeBodyRead.

@Override
public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter methodParameter, Type targetType, Class<? extends HttpMessageConverter<?>> selectedConverterType) throws IOException {
    JsonView annotation = methodParameter.getParameterAnnotation(JsonView.class);
    Class<?>[] classes = annotation.value();
    if (classes.length != 1) {
        throw new IllegalArgumentException("@JsonView only supported for request body advice with exactly 1 class argument: " + methodParameter);
    }
    return new MappingJacksonInputMessage(inputMessage.getBody(), inputMessage.getHeaders(), classes[0]);
}
Also used : MappingJacksonInputMessage(org.springframework.http.converter.json.MappingJacksonInputMessage) JsonView(com.fasterxml.jackson.annotation.JsonView)

Aggregations

JsonView (com.fasterxml.jackson.annotation.JsonView)1 MappingJacksonInputMessage (org.springframework.http.converter.json.MappingJacksonInputMessage)1