Skip to content
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

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

Closed
spring-projects-issues opened this issue Jun 27, 2017 · 0 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jun 27, 2017

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

2 participants