泽西岛可以生成List<T>但不能Responser.ok(List<T>).build()?
2022-09-01 20:53:54
泽西岛1.6可以生产:
@Path("/stock")
public class StockResource {
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Stock> get() {
Stock stock = new Stock();
stock.setQuantity(3);
return Lists.newArrayList(stock);
}
}
但不能对以下情况做同样的事情:
@Path("/stock")
public class StockResource {
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response get() {
Stock stock = new Stock();
stock.setQuantity(3);
return Response.ok(Lists.newArrayList(stock)).build();
}
}
给出错误:A message body writer for Java class java.util.ArrayList, and Java type class java.util.ArrayList, and MIME media type application/json was not found
这可以防止使用 HTTP 状态代码和标头。