【发布时间】:2019-07-06 15:42:00
【问题描述】:
我有以下 JSON 响应:
{
"Count": 1,
"Products": [
{
"ProductID": 3423
},
{
"ProductID": 4321
}
]
}
我希望能够使用 WebClient 从 Products 数组中返回“Product”列表,而无需使用字段“ArrayList products”创建单独的 Dto 类
我用过这样的东西
webClient.get()
.uri(uriBuilder -> uriBuilder
.path(URI_PRODUCTS)
.build())
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToFlux(Product.class)
.collectList();
它检索一个包含一个产品但所有值都为空的列表。我能够让它与 DTO 响应一起工作,例如
...retrieve().bodyToMono(ProductResponse.class).block();
ProductResponse 中包含产品列表的位置。但我试图避免创建额外的类。有没有类似于使用jsonPath(类似于WebTestClient)拉取字段的方法?
【问题讨论】:
标签: json spring response webclient project-reactor