Closed
Description
Ricardo Lindooren opened SPR-15866 and commented
I'm using Webclient
to consume a webservice that uses a legacy mime type for JSON: text/javascript
.
This works when using the Webclient builder.
@Autowired
public ItunesAlbumServiceImpl(ObjectMapper mapper) {
ExchangeStrategies strategies = ExchangeStrategies.builder().codecs(clientCodecConfigurer ->
clientCodecConfigurer.customCodecs().decoder(
new Jackson2JsonDecoder(mapper,
new MimeType("text", "javascript", StandardCharsets.UTF_8)))
).build();
webClient = WebClient.builder()
.exchangeStrategies(strategies)
.baseUrl("https://itunes.apple.com")
.build();
}
But when trying to configure this on application level it doesn't work.
@SpringBootApplication
public class SpringReactiveApplication {
public static void main(String[] args) {
SpringApplication.run(SpringReactiveApplication.class, args);
}
@Bean
public CodecCustomizer jacksonLegacyJsonCustomizer(ObjectMapper mapper) {
return (configurer) -> {
MimeType textJavascript = new MimeType("text", "javascript", StandardCharsets.UTF_8);
CodecConfigurer.CustomCodecs customCodecs = configurer.customCodecs();
customCodecs.decoder(
new Jackson2JsonDecoder(mapper, textJavascript));
customCodecs.encoder(
new Jackson2JsonEncoder(mapper, textJavascript));
};
}
}
While stepping through the code I noticed that the Jackson2JsonDecoder.getDecodableMimeTypes()
and Jackson2JsonEncoder.getEncodableMimeTypes()
methods always return the default JSON mime types, not the one(s) provided as constructor argument.
public class Jackson2JsonDecoder extends AbstractJackson2Decoder {
public Jackson2JsonDecoder() {
super(Jackson2ObjectMapperBuilder.json().build());
}
public Jackson2JsonDecoder(ObjectMapper mapper, MimeType... mimeTypes) {
super(mapper, mimeTypes);
}
@Override
public List<MimeType> getDecodableMimeTypes() {
return JSON_MIME_TYPES;
}
}
Causing Jackson2CodecSupport.supportsMimeType
to return false
for the provided mime types.
Looks related to #20034
I created this PR with a proposed change: 1499
Affects: 5.0 RC3
Referenced from: commits bb327b9