我看到jackson从2.9开始就支持非阻塞,但是如何与webflux一起使用呢?有演示吗?
最佳答案
以下是如何使用 WebClient 向 Github 的列表存储库 API 发出 GET 请求
public Flux<GithubRepo> listGithubRepositories(String username, String token) {
return webClient.get()
.uri("/user/repos")
.header("Authorization", "Basic " + Base64Utils
.encodeToString((username + ":" + token).getBytes(UTF_8)))
.retrieve()
.bodyToFlux(GithubRepo.class);
}
假设我们有一个名为 GithubRepo 的类来确认 Github 的 API 响应,上述函数将返回 GithubRepo 对象的 Flux。
关于java - 如何在 webflux 中异步解析/写入 json? ObjectMapper 方法是阻塞的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62078075/