我无法将WebClient响应映射到具有泛型和/或Kotlin中的嵌套数据类的数据类。我使用的是带有WebFlux和Reactive MongoDB的Spring 5
这是我的WebClient响应代码和placeholder
对数据类的响应。
.map()
这是我嵌套的数据类。我需要获得变量结果。
var response = CreateBittrexUrl("/account/getbalances", "GET")
.getWebClient()
.map { it to Test.Result::class.java } <-- does not work
.flatMap { it.bodyToMono(Test.Result::class.java) } <-- does not work
.flatMap { it.toEntity(Wrapper<Account>().retrieveSomething()::class.java) } <-- does also not work with generics
通用版本;请注意,我使用内联函数从Generic I插入中获取@JsonIgnoreProperties(ignoreUnknown = true)
data class Test(
@JsonProperty("success") val success: Boolean = false,
@JsonProperty("message") val message: String = "",
@JsonProperty("result") val result: List<Result> = emptyList()
) {
data class Result(
@JsonProperty("Currency") val currency: String?,
@JsonProperty("Balance") val balance: Double,
@JsonProperty("Available") val available: Double,
@JsonProperty("Pending") val pending: Double,
@JsonProperty("CryptoAddress") val cryptoAddress: String?,
@JsonProperty("Requested") val requested: Boolean,
@JsonProperty("Uuid") val uuid: Any?
)
数据。这是class.java
方法
BodyToMono()
以下是执行请求时收到的错误消息:
data class Wrapper<T: Any>(var succes: Boolean? = false,
var message: String? = "",
var result: T? = null) {
inline fun <reified T: Any> retrieveSomething() = T::class.java
}