-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Support @RequestBody
in interface method when computing "consumes" condition
#35086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Support @RequestBody
in interface method when computing "consumes" condition
#35086
Conversation
529b666
to
a69ef16
Compare
23d7714
to
8a5bfb0
Compare
8a5bfb0
to
b862eb0
Compare
Thank you @renatomameli. We really rely on this fix and it would be great if we can get this in an upcoming release! @sbrannen |
@RequestBody
in interface method when computing "consumes" condition
Please note that your In addition, if we were to support processing of In any case, we will discuss within the team whether we want to make this change, and we'll get back to you. Cheers |
b862eb0
to
5035306
Compare
Thanks for the feedback! I’ve renamed them to more accurately reflect their purpose. Looking forward to your team’s decision. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating the test method names.
We have decided to support this feature.
Thus, please introduce analogous support in org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping
as well, including appropriate tests.
...java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java
Outdated
Show resolved
Hide resolved
69b9109
to
7018842
Compare
Previously, @RequestBody(required = false) annotations declared on interface methods were ignored when resolving the consumes condition. This caused mappings to incorrectly require a request body with a Content-Type such as application/json, even when no body was provided. This change uses AnnotatedMethod to retrieve parameter annotations from both the implementation and its interfaces, ensuring that the required flag is respected and body presence is evaluated correctly. Signed-off-by: Renato Mameli <renatomamel410@gmail.com>
7018842
to
41b755e
Compare
Thanks for the feedback. I’ve implemented the support in |
Problem
Spring currently ignores
@RequestBody
annotations declared on interface methods when computing theConsumesCondition
. As a result, therequired = false
flag is not respected, and requests without a body and without a Content-Type fail to match the mapping — even though null should be allowed.This leads to situations where e.g.
application/json
is unnecessarily enforced in the ConsumesCondition, despite@RequestBody(required = false)
being declared (e.g., on an interface method).Solution
This change switches to using
AnnotatedMethod
for inspecting method parameters, which ensures that annotations from both interface and implementation methods are considered. This allows Spring to correctly determine whether a request body is required and to avoid enforcing a Content-Type match when required = false.Tests
Includes tests verifying correct behavior for:
@RequestBody(required = false)
required = true