Polishing
This commit is contained in:
@@ -33,13 +33,7 @@ import org.springframework.http.server.ServerHttpResponse;
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.1
|
||||
*/
|
||||
public abstract class AbstractMappingJacksonResponseBodyAdvice
|
||||
implements ResponseBodyAdvice<Object> {
|
||||
|
||||
|
||||
protected AbstractMappingJacksonResponseBodyAdvice() {
|
||||
}
|
||||
|
||||
public abstract class AbstractMappingJacksonResponseBodyAdvice implements ResponseBodyAdvice<Object> {
|
||||
|
||||
@Override
|
||||
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
|
||||
@@ -61,7 +55,7 @@ public abstract class AbstractMappingJacksonResponseBodyAdvice
|
||||
* additional serialization instructions) or simply cast it if already wrapped.
|
||||
*/
|
||||
protected MappingJacksonValue getOrCreateContainer(Object body) {
|
||||
return (body instanceof MappingJacksonValue) ? (MappingJacksonValue) body : new MappingJacksonValue(body);
|
||||
return (body instanceof MappingJacksonValue ? (MappingJacksonValue) body : new MappingJacksonValue(body));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,5 +64,4 @@ public abstract class AbstractMappingJacksonResponseBodyAdvice
|
||||
protected abstract void beforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType,
|
||||
MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -35,12 +35,10 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.1
|
||||
*
|
||||
* @see com.fasterxml.jackson.databind.ObjectMapper#writerWithView(Class)
|
||||
*/
|
||||
public class JsonViewResponseBodyAdvice extends AbstractMappingJacksonResponseBodyAdvice {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
|
||||
return (super.supports(returnType, converterType) && returnType.getMethodAnnotation(JsonView.class) != null);
|
||||
|
||||
@@ -40,28 +40,25 @@ public interface ResponseBodyAdvice<T> {
|
||||
/**
|
||||
* Whether this component supports the given controller method return type
|
||||
* and the selected {@code HttpMessageConverter} type.
|
||||
*
|
||||
* @param returnType the return type
|
||||
* @param converterType the selected converter type
|
||||
* @return {@code true} if beforeBodyWrite should be invoked, {@code false} otherwise
|
||||
* @return {@code true} if {@link #beforeBodyWrite} should be invoked, {@code false} otherwise
|
||||
*/
|
||||
boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType);
|
||||
|
||||
/**
|
||||
* Invoked after an {@code HttpMessageConverter} is selected and just before
|
||||
* its write method is invoked.
|
||||
*
|
||||
* @param body the body to be written
|
||||
* @param returnType the return type of the controller method
|
||||
* @param selectedContentType the content type selected through content negotiation
|
||||
* @param selectedConverterType the converter type selected to write to the response
|
||||
* @param request the current request
|
||||
* @param response the current response
|
||||
*
|
||||
* @return the body that was passed in or a modified, possibly new instance
|
||||
*/
|
||||
T beforeBodyWrite(T body, MethodParameter returnType,
|
||||
MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType,
|
||||
T beforeBodyWrite(T body, MethodParameter returnType, MediaType selectedContentType,
|
||||
Class<? extends HttpMessageConverter<?>> selectedConverterType,
|
||||
ServerHttpRequest request, ServerHttpResponse response);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user