Skip to content

@RequestBody annotation in interface is ignored [SPR-15714] #20270

Closed
@spring-projects-issues

Description

@spring-projects-issues

Zhihong Zhang opened SPR-15714 and commented

Spring checks super-class/interface for annotation so all Spring annotations are inherited. This works for @RequestMapping and @RequestParam. However, it doesn't work for @RequestBody. This is inconsistent at least.

In the attached example, @RequestMapping is inherited but body doesn't get the JSON because @RequestBody in interface is ignored.

To reproduce the error, run the App.java and run this curl command,

curl -H “Content-Type: application/json” -X POST -d ‘{“bar”:“world”}’ http://localhost:8080/test?foo=hello
public interface TestApi {

    @RequestMapping(value = "/test", produces = { "text/html" })
    @ResponseBody
    String test(
            @RequestParam String foo,
            @RequestBody Map<String, Object> body
    );

}

@Controller
public class TestController implements TestApi {
    public String test(String foo, Map<String, Object> body) {
        String bar;
        if (body == null) {
            bar = null;
        } else {
            bar = (String)(body.get("bar"));
        }
        return "<h1>foo=" + foo + "<br>bar=" + bar + "</h1>";
    }
}

Affects: 4.3.7

Attachments:

Issue Links:

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: duplicateA duplicate of another issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions