Skip to content

@RequestBody should have a required parameter to allow a request body to be optional [SPR-9239] #13877

Closed

Description

@spring-projects-issues

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:

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

1 votes, 3 watchers

Activity

  1. spring-projects-issues commented on Mar 20, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Chris Beams commented

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

  2. spring-projects-issues commented on Oct 29, 2012

    @spring-projects-issues
    CollaboratorAuthor

    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?

  3. spring-projects-issues commented on Oct 31, 2012

    @spring-projects-issues
    CollaboratorAuthor

    Rossen Stoyanchev commented

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

  4. spring-projects-issues commented on Feb 7, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Izek Greenfield commented

    I see this problem happen in version 4.2.3-RELEASE

  5. added
    type: enhancement
    in: core
    on Jan 11, 2019
  6. added this to the 3.2 M1 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coretype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions