Skip to content

Add support for @RequestMapping method return values of type ListenableFuture [SPR-11695] #16317

@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions