【发布时间】:2021-11-16 08:29:39
【问题描述】:
我想为一个对象收集以下数据。
{
"success": true,
"symbols": {
"AED": "United Arab Emirates Dirham",
"AFN": "Afghan Afghani",
"ALL": "Albanian Lek"
}
}
我们的对象是这样的;
public class Currencies {
public String success;
public List<ExternalCurrency> currencyList;
}
public class ExternalCurrency {
public String shortCode;
public String name;
}
如何在 Spring Boot 中使用 WebClient 收集 JSON 数据?
谢谢
【问题讨论】:
-
到目前为止你尝试了什么?
-
我尝试使用 json2csharp.com/json-to-pojo 。但它给了我两个类以下 public class ExternalCurrency { @JsonProperty("AED") public String aED; @JsonProperty("AFN") 公共字符串 aFN; @JsonProperty("ALL") public String all; } 公共类货币{ 公共布尔成功;公共外部货币符号;我不想这样。因为也许明天我会添加一种新货币
-
最终 WebClient webClient = WebClient.builder().baseUrl("-----").build();最终货币数据= webClient.get().retrieve().bodyToMono(Currencies.class).block();
标签: json spring spring-boot spring-webclient