我正在使用 Spring 5 WebClient 进行外部 api 调用,并希望将响应映射到这样的对象:
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public static class Response {
private long length;
}
private Mono<Response> getResponse() {
return webClient.get()
.uri("someURI")
.accept(MediaType.APPLICATION_JSON_UTF8)
.retrieve()
.bodyToMono(Response.class);
}
Run Code Online (Sandbox Code Playgroud)
但我收到一个错误:
org.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type 'application/octet-stream' not supported
Run Code Online (Sandbox Code Playgroud)
但是,如果我像这样将响应正文提取到字符串中:
private Mono<String> getResponse() {
return webClient.get()
.uri("someURI")
.accept(MediaType.APPLICATION_JSON_UTF8)
.retrieve()
.bodyToMono(String.class);
}
Run Code Online (Sandbox Code Playgroud)
然后它可以正常工作。任何想法如何解决这个问题?
编辑:
响应体:
{
"blocks": [
{
"height": 545551,
"size": 48289,
"virtualSize": 48289,
"hash": "000000000000000000541d265115ec188544420c4b0e5dff6f2171e17e4991c9",
"time": 1535551238,
"txlength": 80,
"poolInfo": {}
}
],
"length": 1,
"pagination": {
"next": "2018-08-30", …Run Code Online (Sandbox Code Playgroud)