java - 如何在 Flux.subscribe 之后收集数据以将其作为 json 数组发送?
问题描述
这是我做的一个例子,我应该怎么做才能让处理后的数据将结果列表作为 WS json 响应发送?
@Produces(MediaType.APPLICATION_JSON)
public List<String> tryFlux(@QueryParam("names") List<String> names) {
String[] array = new String[names.size()];
Flux.fromIterable(asList(names.toArray(array))).
doOnNext(this::executeService).doOnError(ex -> handleError(ex, names)).retry(1).subscribe();
return ??; //Need help here
}
解决方案
您可以使用 Mono 包装已解析的值以返回 JSON 数据。
@Produces(MediaType.APPLICATION_JSON)
public Mono<JSONResponseObject> tryFlux(@QueryParam("names") List<String> names) {
String[] array = new String[names.size()];
Flux.fromIterable(asList(names.toArray(array))).
doOnNext(this::executeService).doOnError(ex -> handleError(ex, names)).retry(1).subscribe();
return Mono.just(jsonResponseObject); //Need help here
}
推荐阅读
- javascript - FlatList 在 react-native 中的 CRUD 之后没有更新
- ios - 如何处理错误:对象作为 React 子对象无效
- ios - 将数据从注释发送到表格视图单元格
- php - Chrome打开乱码
- mit-scratch - 如何在 Scratch 中遍历列表并打印大于 50 的数字?
- java - 关闭多个语句和结果集的有效方法?
- wso2 - 用户登录 WSO2 身份服务器后如何获取用户属性
- javascript - 使用 Places Autocomplete 进行 React-Leaflet Map 重定位
- powershell - 在 Powershell 中解析 CSV 文件
- javascript - HTML自定义悬停光标指针