You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Regression: @RequestBody(required = false) not respected [SPR-13417] #17996
I'm migrating from 4.1.2 to 4.2.1, and am observing a regression.
A RestController method annotated with @RequestMapping(method = POST) and having an argument annotated with @RequestBody(required = false) causes a 415 response to be sent back by Spring MVC if the request doesn't have a body.
This used to work. And the behavior contradicts the javadoc of RequestBody.
BTW, a similar bug used to exist, and had been fixed: #14575.
I couldn't reproduce this issue - this may not be strictly related to the @RequestBody mapping (otherwise we'd probably see an HTTP 400 error), but rather a serialization/deserialization or a content negotiation issue.
Could you give me some clues about your setup?
What is the expected media type? Which serialization technology are you using (Jackson), do you have a specific setup?
I've been trying to reproduce this with a repro project. Let me know how I can amend this project to reproduce this.
I'll have a look to the repro project and try to reproduce and submit a PR, but I can tell you more about my use-case:
The issue disappears if there is a content-type header in the request (set to application/json). But the fact is that sending an HTTP request using angular's $http service, without body, doesn't set a content-type. And that seems logical, since there is no content
This is now fixed.
Because we now support ResponseBodyAdvice for empty bodies, we need to clearly deal with "no body, no content-type" cases separately. I've verified this with our repro project and a local SNAPSHOT.
This should show up in our SNAPSHOTs in as soon as this build is done.
FYI, Spring Boot 1.3 RC1 should ship with Spring Framework 4.2.2 (this fix included).
I've received a notification for this comment as well - this may not be a regression per se, since a unit test was added along the fix for this particular issue.
I've asked for more details on the issue itself.
Activity
spring-projects-issues commentedon Sep 2, 2015
Brian Clozel commented
Hi Jean-Baptiste Nizet
I couldn't reproduce this issue - this may not be strictly related to the
@RequestBodymapping (otherwise we'd probably see an HTTP 400 error), but rather a serialization/deserialization or a content negotiation issue.Could you give me some clues about your setup?
What is the expected media type? Which serialization technology are you using (Jackson), do you have a specific setup?
I've been trying to reproduce this with a repro project. Let me know how I can amend this project to reproduce this.
spring-projects-issues commentedon Sep 2, 2015
Jean-Baptiste Nizet commented
I'll have a look to the repro project and try to reproduce and submit a PR, but I can tell you more about my use-case:
spring-projects-issues commentedon Sep 2, 2015
Jean-Baptiste Nizet commented
Pull request sent, with a unit test reproducing the problem: spring-attic/spring-framework-issues#105
spring-projects-issues commentedon Sep 2, 2015
Brian Clozel commented
Thanks Jean-Baptiste Nizet, I'll look into it.
spring-projects-issues commentedon Sep 3, 2015
Brian Clozel commented
This is now fixed.
Because we now support ResponseBodyAdvice for empty bodies, we need to clearly deal with "no body, no content-type" cases separately. I've verified this with our repro project and a local SNAPSHOT.
This should show up in our SNAPSHOTs in as soon as this build is done.
FYI, Spring Boot 1.3 RC1 should ship with Spring Framework 4.2.2 (this fix included).
Thanks for the report!
spring-projects-issues commentedon Sep 3, 2015
Jean-Baptiste Nizet commented
Thanks for the fix, Brian.
spring-projects-issues commentedon Jan 3, 2016
Sam Brannen commented
Brian Clozel,
It appears there might be a regression in 4.2.3:
Can you please look into this?
spring-projects-issues commentedon Jan 3, 2016
Brian Clozel commented
Hey Sam,
I've received a notification for this comment as well - this may not be a regression per se, since a unit test was added along the fix for this particular issue.
I've asked for more details on the issue itself.
Thanks!