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
Spring Controller is not able to detect empty string ("") as a string object in RequestBody [SPR-13861] #18434
in: coreIssues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently apply
Problem Statement :
Spring Controller is not able to detect empty string ("") as a string object in RequestBody.Till Spring 3.2 Spring Controller is able to detect empty string ("") as a string. But now we upgrade our spring version from 3.2 to 4.2.And in Spring 4.2 we are facing this issue.Our API gives HTTP status 400 as response instead of processing the empty string in RequestBody Example :
Controller Method definition:
We can use public ResponseEntity submitAttempt(@RequestBody(required = false) String eaid).
But this leads to a code change due to spring version upgrade. And this is not recomended.
But if we change the input from a empty string to a blank space (from "" to " ") then it works properly.
Thanks!
As far as I can see, this is intentional in that we fixed the actual meaning of the 'required' flag there. If required=true lets empty bodies through, what's the meaning of required=false?
So from my perspective, you'll have to add required=false, and there's nothing wrong with that. Technically, you always expected required=false behavior but since Spring did accidentally not enforce the meaning of the 'required' flag, your code nevertheless worked even with required=false omitted. In other words, semantically, you should have added required=false in your Spring 3.2 based code already.
Indeed, this is the expected behavior for this feature and we've fixed several bugs lately wrt JSON deserialization and @RequestBody. Let me know if you need further help with this.
in: coreIssues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently apply
Activity
spring-projects-issues commentedon Jan 12, 2016
AVINABA GHOSH HAJRA commented
We can use public ResponseEntity submitAttempt(
@RequestBody(required = false) String eaid).But this leads to a code change due to spring version upgrade. And this is not recomended.
But if we change the input from a empty string to a blank space (from "" to " ") then it works properly.
Thanks!
spring-projects-issues commentedon Jan 18, 2016
AVINABA GHOSH HAJRA commented
Is there any update regarding this issue?
spring-projects-issues commentedon Jan 21, 2016
Juergen Hoeller commented
As far as I can see, this is intentional in that we fixed the actual meaning of the 'required' flag there. If
required=truelets empty bodies through, what's the meaning ofrequired=false?So from my perspective, you'll have to add
required=false, and there's nothing wrong with that. Technically, you always expectedrequired=falsebehavior but since Spring did accidentally not enforce the meaning of the 'required' flag, your code nevertheless worked even withrequired=falseomitted. In other words, semantically, you should have addedrequired=falsein your Spring 3.2 based code already.Juergen
spring-projects-issues commentedon Jan 21, 2016
Brian Clozel commented
Indeed, this is the expected behavior for this feature and we've fixed several bugs lately wrt JSON deserialization and
@RequestBody. Let me know if you need further help with this.Thanks Juergen!
spring-projects-issues commentedon Jan 28, 2016
AVINABA GHOSH HAJRA commented
Thanks guys. This issue can be closed