Closed
Description
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:
- spring-bug.tar (9.00 kB)
Issue Links:
- Enable REST controller method parameter annotations on an interface [SPR-11055] #15682 Enable REST controller method parameter annotations on an interface ("duplicates")
- Supports annotating parameter annotations like @PathVariable on interface method [SPR-16110] #20658 Supports annotating parameter annotations like
@PathVariable
on interface method