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
ResponseBodyAdvice to accept null values? [SPR-12152] #16766
Comments
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? |
Rossen Stoyanchev commented I'll take a closer look, thanks. |
Ken Wang commented Thanks man, much appreciated. |
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. |
Ken Wang commented Thank you for the fix! I hadn't thought about ResponseEntity, hope that wasn't too much of a hurdle. |
Rossen Stoyanchev commented No worries. Thanks for the suggestion. |
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
The text was updated successfully, but these errors were encountered: