我有一個端點
public Page<String> list(String search, Pageable pageable)
api的回應看起來像
{
"content": []。
"a00000",
"b11111"
],
"first": true,
"last": true,
"totalPages": 1,
"totalElements": 2,
"numberOfElements": 2 ,
"size": 2000,
"number": 0,
"pageable": {
"sort": {
"unsorted": true,
"sorted": false
},
"offset": 0,
"pageSize": 2000,
"pageNumber": 0,
"unpaged": false,
"paged": true
}
}
我試圖通過
使用Spring v2.5.0在另一個微服務中消費這個端點。 override fun getNamesById(id。String)。List<String> {
val uri = URIBuilder("$baseUrl/api/names"/span>)
.setParameter("search"/span>, "id==$id")
.build()
try {
val response = restTemplate.exchange(
uri,
HttpMethod.GET,
null)。)
typeReference<RestResponsePage<String>>()
)
return response.body!!.content
} catch (ex: HttpServerErrorException) {
throw handleServerError(ex)
}
}
inline fun <reified T> typeReference() = object : ParameterizedTypeReference<T>() {}。
RestResponsePage的實作是按照這個post來處理分頁回應的。
@JsonIgnoreProperties(ignoreUnknown = true)
public class RestResponsePage< T> extends PageImpl< T> {
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public RestResponsePage(@JsonProperty("content") List<T> content。
@JsonProperty("number") int number。
@JsonProperty("size") int size。
@JsonProperty("totalElements") Long totalElements) {
super(content, PageRequest.of(number, size), totalElements)。
}
public RestResponsePage(List< T> content, Pageable pageable, long total) {
super(content, pageable, total)。
}
public RestResponsePage(List< T> content) {
super(內容)。
}
public RestResponsePage() {
super(new ArrayList<>())。
}
然而,當運行我的應用程式時,我得到了這個錯誤
。java.lang.TypeNotPresentException。Type com.test.RestResponsePage不存在。
...
at com.test.anotherService$getNamesById$$inlined$typeReference$1. <init>(otherService.kt:75)
at com.test.anotherService$getNamesById(anotherService.kt:77)
我怎樣才能正確地消費這個端點?
uj5u.com熱心網友回復:將你的RestResponsePageJava類轉換成Kotlin類。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/309945.html
標籤:
