-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Luciano Leggieri opened SPR-11695 and commented
I created a custom HandlerMethodReturnValueHandler that handles controller methods that return a ListenableFuture (by creating a deferredresult that is filled when the future completes). Then I add it to the AppContext via a WebMvcConfigurer.
I would also like to annotate such method with @ResponseBody
, so I can return, for instance, a ListenableFuture<Long>. It would handle the asynchronous part first, and then convert the Long to a nice response that contains the number.
It works fine with DeferredResult because in org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#getDefaultReturnValueHandlers(), handlers like CallableMethodReturnValueHandler, DeferredResultMethodReturnValueHandler or AsyncTaskMethodReturnValueHandler comes before than RequestResponseBodyMethodProcessor. But any custom handler comes later so the annotation is found first, and the ListenableFuture is converted to json.
Affects: 4.0.3