【发布时间】:2020-10-14 20:36:56
【问题描述】:
在我更新到 spring-boot 2.3.0 之后(所以我的 webflux WebClient 现在是 5.2.6 版)自定义 ObjectMapper 被完全忽略。我的配置如下所示
public static WebClient buildWebClient(WebClient.Builder builder) {
return builder
.defaultHeader(ACCEPT, APPLICATION_JSON_VALUE)
.defaultHeader(HttpHeaders.ACCEPT_ENCODING, "identity")
.exchangeStrategies(ExchangeStrategies
.builder()
.codecs(codecConfigurer -> {
codecConfigurer.defaultCodecs().jackson2JsonDecoder(buildJsonDeserializer());
})
.build())
.build();
}
public static Jackson2JsonDecoder buildJsonDeserializer() {
ObjectMapper customObjectMapper = new ObjectMapper();
SimpleModule simpleModule = new SimpleModule();
simpleModule.addDeserializer(Map.class, new JsonDeserializer<Map<String, String>>() {
@Override
public Map<String, String> deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException {
...
}
});
customObjectMapper.registerModule(simpleModule);
return new Jackson2JsonDecoder(customObjectMapper, MediaType.APPLICATION_JSON);
}
新版本有bug还是只是改了不知道怎么设置?
【问题讨论】:
标签: java spring-boot spring-webflux spring-webclient