Jersey can produce List but cannot Response.ok(List).build()?

前端 未结 3 679
滥情空心
滥情空心 2020-12-24 02:45

Jersey 1.6 can produce:

@Path(\"/stock\")
public class StockResource {
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public List get()          


        
3条回答
  •  -上瘾入骨i
    2020-12-24 03:07

    my solution for methods that use AsyncResponse

    @GET
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public void list(@Suspended
            final AsyncResponse asyncResponse) {
        asyncResponse.setTimeout(10, TimeUnit.SECONDS);
        executorService.submit(() -> {
            List res = super.listProducts();
            Product[] arr = res.toArray(new Product[res.size()]);
            asyncResponse.resume(arr);
        });
    }
    

提交回复
热议问题