我org.springframework.web.reactive.function.client.WebClient
在 Spring Boot (2.0.0.M1) 应用程序中使用来查询返回嵌套数组的 REST 接口:
[
[ "name1", 2331.0, 2323.3 ],
[ "name2", 2833.3, 3838.2 ]
]
我现在正试图将此响应映射到一个Flux
对象。为此,我进行了以下调用:
WebClient webClient = WebClient.create("http://example.org");
Flux<Result> results = webClient.get().uri("/query").
accept(MediaType.APPLICATION_JSON_UTF8).
exchange().
flatMapMany(response -> response.bodyToFlux(Result.class));
Result 类看起来像这样:
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.math.BigDecimal;
@Data
@JsonFormat(shape = JsonFormat.Shape.ARRAY)
public class Result {
private final String name;
private final BigDecimal value1;
private final BigDecimal value2;
@JsonCreator
public Result(
@JsonProperty String name,
@JsonProperty BigDecimal value1,
@JsonProperty BigDecimal value2) {
this.name = name;
this.value1 = value1;
this.value2 = value2;
}
}
不幸的是,我收到以下错误:
org.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type 'application/json;charset=utf-8' not supported
谁能告诉我我做错了什么或告诉我一种更好的方法将这种响应反序列化为 Flux,最好以非阻塞方式?