Skip to content

@RequestBody annotation on interface methods ignored for required flag #35085

Closed as not planned
@renatomameli

Description

@renatomameli

When @RequestBody(required = false) is declared on a controller interface method, Spring currently ignores this annotation during request mapping. As a result, mappings incorrectly require a request body even when required = false is set on the interface.

This leads to incorrect matching behavior, especially when the implementation method does not override the @RequestBody annotation.

Expected behavior:
Spring should detect the @RequestBody annotation on interface methods and respect the required flag during request mapping, allowing requests without bodies when required = false.

Actual behavior:
Only the annotations on the implementation method are considered, causing required = false on interfaces to be ignored.

Steps to reproduce:

  • Define a controller interface method annotated with @RequestBody(required = false)
  • Implement the interface without overriding the annotation
  • Register the handler and observe that Spring expects a body even if required = false
  • Make a request with no body and no Content-Type and observe that the request fails

Suggested fix:
Use AnnotatedMethod to retrieve parameter annotations from both implementation and interface methods to correctly determine the required flag.

Additional context:
I have a patch that fixes this and adds tests to cover both interface and implementation overrides.

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: supersededAn issue that has been superseded by another

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions