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 should have a required parameter to allow a request body to be optional [SPR-9239] #13877

Closed
spring-projects-issues opened this issue Mar 14, 2012 · 4 comments

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Mar 14, 2012

Michel Zanini opened SPR-9239 and commented

@RequestBody should have a required parameter to allow a request body to be optional, if the body is empty my object is null, otherwise it is parsed using a http message converter.

At the moment I am using a Jackson (JSON) converter and if I use it as bellow:

@RequestMapping(method = RequestMethod.POST, value = "/url")
public String method(@RequestBody MyBody myBody) {
...
}

Then, if I send an empty body it will throw an java.io.EOFException.
In this case I would like to receive null in myBody and execute my method anyway.

This issue maybe related to https://jira.springsource.org/browse/SPR-9238.


Affects: 3.1.1

Issue Links:

  • #16447 Contract of @RequestBody(required=true) not obeyed
  • #13876 JSON (jackson) @RequestBody marshalling throws java.io.EOFException when body is missing
  • #14575 HttpMessageNotReadableException when @RequestBody(required=false)
  • #19574 Support for java.util.Optional as a @RequestBody

Referenced from: commits spring-projects/spring-framework-issues@208a6cb

1 votes, 3 watchers

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 20, 2012

Chris Beams commented

Assigning to you @Arjen as this looks closely related to #13876 (which you are also assigned to). Added @Rossen as watcher.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 29, 2012

David Roberts commented

Iv tested this on 3.2M2 and set @RequestBody(required=false), and it is still throwing org.springframework.http.converter.HttpMessageNotReadableException when I send it a null body from a test client. I would expect my body object parameter to be sent through as null, as per the comments on the @RequestBody.required() method.

Any suggestions?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 31, 2012

Rossen Stoyanchev commented

I've created a new issue #14575 to track the reported problem.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 7, 2016

Izek Greenfield commented

I see this problem happen in version 4.2.3-RELEASE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants