Closed
Description
Daniel Lavoie opened SPR-15474 and commented
Some web services offers JSON content without properly typing the content type. For example, a bad api serving json content but setting the content-type to text/plain. The brand new shiny WebClient relies on the Jackson2CodecSupport to decode the stream. Saldy, there is now way to manually define the supported mime types.
The class Jackson2CodecSupport does not offers any means to override the supported mime types.
I can provide a PR to expose an extension mechanism.
Jackson2JsonDecoder
@Override
public boolean canDecode(ResolvableType elementType, MimeType mimeType) {
JavaType javaType = this.objectMapper.getTypeFactory().constructType(elementType.getType());
// Skip String: CharSequenceDecoder + "*/*" comes after
return (!CharSequence.class.isAssignableFrom(elementType.resolve(Object.class)) &&
this.objectMapper.canDeserialize(javaType) && supportsMimeType(mimeType));
}
Jackson2CodecSupport
protected static final List<MimeType> JSON_MIME_TYPES = Arrays.asList(
new MimeType("application", "json", StandardCharsets.UTF_8),
new MimeType("application", "*+json", StandardCharsets.UTF_8));
protected boolean supportsMimeType(MimeType mimeType) {
return (mimeType == null ||
JSON_MIME_TYPES.stream().anyMatch(m -> m.isCompatibleWith(mimeType)));
}
Affects: 5.0 M1
Referenced from: commits 8231812