Skip to content

ResponseBodyAdvice to accept null values? [SPR-12152] #16766

Closed

Description

@spring-projects-issues

Ken Wang opened SPR-12152 and commented

ResponseBodyAdvice is amazing for my needs except for one thing, it doesn't seem to be triggered when the ResponseBody returns a null value.

Is it possible to handle this case through the ResponseBodyAdvice?


Affects: 4.1 GA

Issue Links:

0 votes, 5 watchers

Activity

  1. spring-projects-issues commented on Sep 6, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Ken Wang commented

    So I looked through the source code and found the deciding piece in the function RequestResponseBodyMethodProcessor.handleReturnValue(). In this function there is a null check that only runs AbstractMessageConverterMethodProcessor.writeWithMessageConverters() if returnValue is not null.

    As far as I can tell by following the call chain, this returnValue is only required to be nonnull by the function AbstractMessageConverterMethodProcessor.writeWithMessageConverters() in which returnValue.getClass() is called.

    However, if I understand it properly, this value can be obtained by returnType.getMethod().getReturnType().

    So ideally, I'd like to get rid of this null check in RequestResponseBodyMethodProcessor.handleReturnValue(). Would this be a viable solution?

  2. spring-projects-issues commented on Sep 7, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Rossen Stoyanchev commented

    I'll take a closer look, thanks.

  3. spring-projects-issues commented on Sep 8, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Ken Wang commented

    Thanks man, much appreciated.

  4. spring-projects-issues commented on Sep 19, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Rossen Stoyanchev commented

    I've added a fix. It turned out to be a little more complex since the return type could be ResponseEntity<?> in which case we've to obtain the generic parameter type.

  5. spring-projects-issues commented on Sep 19, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Ken Wang commented

    Thank you for the fix! I hadn't thought about ResponseEntity, hope that wasn't too much of a hurdle.

  6. spring-projects-issues commented on Sep 20, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Rossen Stoyanchev commented

    No worries. Thanks for the suggestion.

  7. added
    type: enhancement
    in: web
    on Jan 11, 2019
  8. added this to the 4.1.1 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: webtype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions