Skip to content

Commit e6fd7ab

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 aa575c3 commit e6fd7ab

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.
@@ -38,6 +38,7 @@
3838
* {@link org.springframework.web.method.ControllerAdviceBean ControllerAdviceBean}.
3939
*
4040
* @author Rossen Stoyanchev
41+
* @author Sam Brannen
4142
* @since 4.2
4243
*/
4344
class RequestResponseBodyAdviceChain implements RequestBodyAdvice, ResponseBodyAdvice<Object> {
@@ -49,7 +50,7 @@ class RequestResponseBodyAdviceChain implements RequestBodyAdvice, ResponseBodyA
4950

5051
/**
5152
* Create an instance from a list of objects that are either of type
52-
* {@code ControllerAdviceBean} or {@code RequestBodyAdvice}.
53+
* {@code RequestBodyAdvice} or {@code ResponseBodyAdvice}.
5354
*/
5455
public RequestResponseBodyAdviceChain(@Nullable List<Object> requestResponseBodyAdvice) {
5556
if (requestResponseBodyAdvice != null) {
@@ -60,7 +61,7 @@ public RequestResponseBodyAdviceChain(@Nullable List<Object> requestResponseBody
6061
if (RequestBodyAdvice.class.isAssignableFrom(beanType)) {
6162
this.requestBodyAdvice.add(advice);
6263
}
63-
else if (ResponseBodyAdvice.class.isAssignableFrom(beanType)) {
64+
if (ResponseBodyAdvice.class.isAssignableFrom(beanType)) {
6465
this.responseBodyAdvice.add(advice);
6566
}
6667
}

0 commit comments

Comments
 (0)