0
我在春天启动(2.0.0.M1)应用程序中使用org.springframework.web.reactive.function.client.WebClient
查询一个REST接口,它返回一个嵌套的数组:如何使用Spring WebClient将嵌套JSON数组反序列化为Flux?
[
[ "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));
结果类看起来是这样的:
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,最好是以非阻塞的方式?
我有同样的问题;然而,上面的答案不适用于我。任何人都可以帮忙谢谢 – Wenyan
请在SO上单独发布问题 –