我正在使用Vert.x为我的类Java数据库服务制作REST api。 这不是太难治写JSON结果作为字符串请求的流,如下图所示:如何在Vert.x中使用杰克逊的JSON结果流(Java)
...
routeMatcher.get("/myservice/api/v1/query/:query", req -> {
// get query
String querySring = req.params().get("query");
Query query = jsonMapper.readValue(querySring, Query.class);
// my service creates a list of resulting records...
List<Record> result = myservice.query(query);
String jsonResult = jsonMapper.writeValueAsString(result);
// write entire string to response
req.response().headers().set("Content-Type", "application/json; charset=UTF-8");
req.response().end(jsonResult);
});
...
不过,我想用杰克逊的方法以流式Java列表请求对象:
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.writeValue(Outputstream, result);
但我不知道如何杰克逊的OutputStream参数连接到Vert.x的re.response(),因为他们有自己的Buffer系统,似乎与杰克逊的java.io.OutputStream中的说法不符。
我不能将Jackson与Vert.x结合使用吗?我应该用Vert.x自己的JSON library手动编写自定义序列化程序吗?其他建议?