json - 如何使用 Kotlin 操作 Mono 对象
问题描述
大家好,我正在使用 webflux 和 kotlin 开发一个 API。我的问题很简单,我需要在使用 API 时操作返回给我的 Flux 对象的属性,这是伤害我的对象
postId": 14,
"userId": 2,
"title": "voluptatem eligendi optio",
"comments": [
{
"email": "Janice@alda.io",
"body": "necessitatibus libero occaecati\nvero inventore iste assumenda veritatis\nasperiores non sit et quia omnis facere nemo explicabo\nodit quo nobis porro"
}
]
这是我的控制器,它发出请求并返回之前的 JSON 对象
fun getData(): Flux<Post> {
return apiService.fetchPosts()
}
这是我使用 API 的服务代码
@Service
class APIService {
fun fetchComments(postId:Int) =
fetch("posts/$postId/comments").bodyToFlux(Comment::class.java)
fun fetchPosts() =
fetch("/posts").bodyToFlux(Post::class.java)
fun fetch(path:String): WebClient.ResponseSpec {
val client = WebClient.create("http://jsonplaceholder.typicode.com/")
return client.get().uri(path).retrieve()
}
}
谢谢
解决方案
推荐阅读
- qt - 终端在 Qt 中无法正常工作
- rust - 为什么我在使用本地 Futures 执行程序时会收到不匹配的类型错误(预期的 mpsc::Receiver, found ())?
- php - 使用 ip 地址在数据库上查找 CIDR 并进行 closesd 匹配
- spring-boot - spring-boot 找不到 sqlite 驱动
- python - Python DataFrame循环和切片问题
- javascript - 从 ARROW 函数 (es6) 到 ES5
- drupal - 永久删除 Drupal 8 中未使用/孤立的文件
- python - jupyterlab 交互式绘图
- java - Spring 应用程序不能在 JBOSS 中运行,但可以与 Tomcat 一起使用
- amazon-web-services - Terraform EMR 调整大小,破坏整个集群