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上單獨發佈問題 –