Description
Rossen Stoyanchev opened SPR-13742 and commented
@RequestBody
converts the body of the request to an object while @ModelAttribute
binds request parameters to an object. The former is common with REST APIs while the latter is common with HTML forms in browser applications.
JavaScript UI components however may send HTTP GET requests via Ajax with data represented either as JSON input in the body or appended as query parameters. See relevant discussion under SPR-13679. It would be useful to have a single controller method argument that supports both.
One way to do this could be to delegate to either @RequestBody
or @ModelAttribute
argument resolution. However for the given use case it may make more sense to somehow fold this together with @RequestBody
handling such that we either read the body or treat request parameters as form data. This is something we already do for HTTP POST albeit for a different reason (i.e. to avoid issues where a call to getParameter from a Filter causes the request body to be consumed before we try to read it). This would also be a more consistent and simpler to understand approach, effectively it can still be thought of as @RequestBody
handling. It would also be suited for the given use case, i.e. Ajax requests where for example a 400 response is perfectly okay for error responses (vs rendering an HTML error page).
Affects: 4.2.3
Issue Links:
- @RestController avoid declare @RequestBody too [SPR-13868] #18441
@RestController
avoid declare@RequestBody
too - True Content-Negotiation [SPR-13679] #18254 True Content-Negotiation ("supersedes")
Referenced from: commits spring-attic/spring-framework-issues@cdde05b
2 votes, 8 watchers