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
ResponseBodyAdvice to accept null values? [SPR-12152] #16766
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?
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.
Activity
spring-projects-issues commentedon Sep 6, 2014
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?
spring-projects-issues commentedon Sep 7, 2014
Rossen Stoyanchev commented
I'll take a closer look, thanks.
spring-projects-issues commentedon Sep 8, 2014
Ken Wang commented
Thanks man, much appreciated.
spring-projects-issues commentedon Sep 19, 2014
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.
spring-projects-issues commentedon Sep 19, 2014
Ken Wang commented
Thank you for the fix! I hadn't thought about ResponseEntity, hope that wasn't too much of a hurdle.
spring-projects-issues commentedon Sep 20, 2014
Rossen Stoyanchev commented
No worries. Thanks for the suggestion.