Skip to content

Commit 47e88aa

Browse files
committed
Allow ResponseBodyAdvice to implement RequestBodyAdvice
Prior to this commit, if a @ControllerAdvice bean implemented both RequestBodyAdvice and ResponseBodyAdvice, it was only supported as RequestBodyAdvice, meaning it was never invoked as ResponseBodyAdvice. This commit revises RequestResponseBodyAdviceChain to ensure that a single bean implementing both types of body advice is in fact handled as both types of advice. See gh-22638
1 parent afe037e commit 47e88aa

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyAdviceChain.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,6 +37,7 @@
3737
* {@link org.springframework.web.method.ControllerAdviceBean ControllerAdviceBean}.
3838
*
3939
* @author Rossen Stoyanchev
40+
* @author Sam Brannen
4041
* @since 4.2
4142
*/
4243
class RequestResponseBodyAdviceChain implements RequestBodyAdvice, ResponseBodyAdvice<Object> {
@@ -48,7 +49,7 @@ class RequestResponseBodyAdviceChain implements RequestBodyAdvice, ResponseBodyA
4849

4950
/**
5051
* Create an instance from a list of objects that are either of type
51-
* {@code ControllerAdviceBean} or {@code RequestBodyAdvice}.
52+
* {@code RequestBodyAdvice} or {@code ResponseBodyAdvice}.
5253
*/
5354
public RequestResponseBodyAdviceChain(List<Object> requestResponseBodyAdvice) {
5455
initAdvice(requestResponseBodyAdvice);
@@ -64,7 +65,7 @@ private void initAdvice(List<Object> requestResponseBodyAdvice) {
6465
if (RequestBodyAdvice.class.isAssignableFrom(beanType)) {
6566
this.requestBodyAdvice.add(advice);
6667
}
67-
else if (ResponseBodyAdvice.class.isAssignableFrom(beanType)) {
68+
if (ResponseBodyAdvice.class.isAssignableFrom(beanType)) {
6869
this.responseBodyAdvice.add(advice);
6970
}
7071
}

0 commit comments

Comments
 (0)