Spring Framework
  1. Spring Framework
  2. SPR-8016

RestTemplate - support response mapping to entity with potentially empty response body.

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 3.1 M1
    • Fix Version/s: Waiting for Triage
    • Component/s: Core
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      I am working with an API which returns an empty response body on http status 200 (OK) & a body which is populated on http status 400 (Bad Request).

      When using RestTemplate.getForEntity() this is fine for the case where the body is populated, however I get an exception for the 'null body' case.

      My understanding is one should provide a class implementing the ResponseBody interface & make the call via the execute() method on the RestTemplate.

      This task is a request to consider that the use case here is common & whether Spring should offer something out of the box for this situation.

      Also See: http://stackoverflow.com/questions/3322381/spring-resttemplate-behavior-when-handling-responses-with-a-status-of-no-content/3648447#3648447

        Activity

        Hide
        sriram added a comment -

        Same issue for post calls that return 202 accepted with an empty body.

        Show
        sriram added a comment - Same issue for post calls that return 202 accepted with an empty body.
        Hide
        emanuele added a comment -

        Same issue for post calls returning 204 - NO CONTENT. The only way to use rest template with this kind of response is to set "null" as ResponseEntity class, but doing so you can't know what response really you had with your call.

        Show
        emanuele added a comment - Same issue for post calls returning 204 - NO CONTENT. The only way to use rest template with this kind of response is to set "null" as ResponseEntity class, but doing so you can't know what response really you had with your call.
        Hide
        Shai Yallin added a comment -

        Same issue for any request resulting in 304 Not Modified

        Show
        Shai Yallin added a comment - Same issue for any request resulting in 304 Not Modified
        Hide
        Magnus Heino added a comment -

        Already fixed.

        SPR-7911

        Show
        Magnus Heino added a comment - Already fixed. SPR-7911
        Hide
        David Victor added a comment -

        Several options documented here too. http://stackoverflow.com/a/5170959/366073

        Show
        David Victor added a comment - Several options documented here too. http://stackoverflow.com/a/5170959/366073

          People

          • Assignee:
            Unassigned
            Reporter:
            David Victor
            Last updater:
            Chris Beams
          • Votes:
            9 Vote for this issue
            Watchers:
            11 Start watching this issue

            Dates

            • Created:
              Updated:
              Days since last comment:
              1 year, 25 weeks, 3 days ago