Polishing
This commit is contained in:
@@ -28,22 +28,23 @@ import org.springframework.http.converter.json.AbstractJackson2HttpMessageConver
|
||||
import org.springframework.http.converter.json.MappingJacksonInputMessage;
|
||||
|
||||
/**
|
||||
* A {@code RequestBodyAdvice} implementation that adds support for
|
||||
* Jackson's {@code @JsonView} annotation declared on a Spring MVC
|
||||
* {@code @HttpEntity} and {@code @RequestBody} method parameters.
|
||||
* A {@link RequestBodyAdvice} implementation that adds support for Jackson's
|
||||
* {@code @JsonView} annotation declared on a Spring MVC {@code @HttpEntity}
|
||||
* or {@code @RequestBody} method parameter.
|
||||
*
|
||||
* <p>The deserialization view specified in the annotation will be passed in to
|
||||
* the {@code MappingJackson2HttpMessageConverter} which will then use it to
|
||||
* deserialize the request body with.
|
||||
* <p>The deserialization view specified in the annotation will be passed in to the
|
||||
* {@link org.springframework.http.converter.json.MappingJackson2HttpMessageConverter}
|
||||
* which will then use it to deserialize the request body with.
|
||||
*
|
||||
* <p>Note that despite {@code @JsonView} allowing for more than one class to
|
||||
* be specified, the use for a request body advice is only supported with
|
||||
* exactly one class argument. Consider the use of a composite interface.
|
||||
*
|
||||
* <p>Jackson 2.5.0 or later is required.
|
||||
* <p>Jackson 2.5 or later is required for parameter-level use of {@code @JsonView}.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 4.2
|
||||
* @see com.fasterxml.jackson.annotation.JsonView
|
||||
* @see com.fasterxml.jackson.databind.ObjectMapper#readerWithView(Class)
|
||||
*/
|
||||
public class JsonViewRequestBodyAdvice extends RequestBodyAdviceAdapter {
|
||||
@@ -51,6 +52,7 @@ public class JsonViewRequestBodyAdvice extends RequestBodyAdviceAdapter {
|
||||
@Override
|
||||
public boolean supports(MethodParameter methodParameter, Type targetType,
|
||||
Class<? extends HttpMessageConverter<?>> converterType) {
|
||||
|
||||
return (AbstractJackson2HttpMessageConverter.class.isAssignableFrom(converterType) &&
|
||||
methodParameter.getParameterAnnotation(JsonView.class) != null);
|
||||
}
|
||||
@@ -58,6 +60,7 @@ public class JsonViewRequestBodyAdvice extends RequestBodyAdviceAdapter {
|
||||
@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) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,13 +26,13 @@ import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
|
||||
/**
|
||||
* A {@code ResponseBodyAdvice} implementation that adds support for
|
||||
* Jackson's {@code @JsonView} annotation declared on a Spring MVC
|
||||
* {@code @RequestMapping} or {@code @ExceptionHandler} method.
|
||||
* A {@link ResponseBodyAdvice} implementation that adds support for Jackson's
|
||||
* {@code @JsonView} annotation declared on a Spring MVC {@code @RequestMapping}
|
||||
* or {@code @ExceptionHandler} method.
|
||||
*
|
||||
* <p>The serialization view specified in the annotation will be passed in to
|
||||
* the {@code MappingJackson2HttpMessageConverter} which will then use it to
|
||||
* serialize the response body with.
|
||||
* <p>The serialization view specified in the annotation will be passed in to the
|
||||
* {@link org.springframework.http.converter.json.MappingJackson2HttpMessageConverter}
|
||||
* which will then use it to serialize the response body with.
|
||||
*
|
||||
* <p>Note that despite {@code @JsonView} allowing for more than one class to
|
||||
* be specified, the use for a response body advice is only supported with
|
||||
@@ -40,6 +40,7 @@ import org.springframework.http.server.ServerHttpResponse;
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.1
|
||||
* @see com.fasterxml.jackson.annotation.JsonView
|
||||
* @see com.fasterxml.jackson.databind.ObjectMapper#writerWithView(Class)
|
||||
*/
|
||||
public class JsonViewResponseBodyAdvice extends AbstractMappingJacksonResponseBodyAdvice {
|
||||
|
||||
Reference in New Issue
Block a user