Support @RequestBody
in interface method when computing "consumes" condition
#35086
+75
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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