-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Closed as not planned
Closed as not planned
Copy link
Labels
for: external-projectNeeds a fix in external projectNeeds a fix in external projectin: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancementA general enhancement
Description
I currently have to deal with a REST API using text/xml;charset=ISO-8859-1 as MediaType. So just using MappingJackson2XmlHttpMessageConverter seemed obvious to me. Unfortunately I found myself with
RestClientException: No HttpMessageConverter for ... and content type "text/xml;charset=ISO-8859-1"
As it turns out, inheriting from AbstractJackson2HttpMessageConverter checks for hard-coded UTF encodings when calling MappingJackson2XmlHttpMessageConverter.canWrite()
Lines 84 to 92 in 65553f5
| private static final Map<String, JsonEncoding> ENCODINGS; | |
| static { | |
| ENCODINGS = CollectionUtils.newHashMap(JsonEncoding.values().length); | |
| for (JsonEncoding encoding : JsonEncoding.values()) { | |
| ENCODINGS.put(encoding.getJavaName(), encoding); | |
| } | |
| ENCODINGS.put("US-ASCII", JsonEncoding.UTF8); | |
| } |
Lines 273 to 283 in 65553f5
| public boolean canWrite(Class<?> clazz, @Nullable MediaType mediaType) { | |
| if (!canWrite(mediaType)) { | |
| return false; | |
| } | |
| if (mediaType != null && mediaType.getCharset() != null) { | |
| Charset charset = mediaType.getCharset(); | |
| if (!ENCODINGS.containsKey(charset.name())) { | |
| return false; | |
| } | |
| } | |
| ObjectMapper objectMapper = selectObjectMapper(clazz, mediaType); |
which is totally reasonable for JSON but not for XML. Overriding this method is not a problem at all but I wanted you to be notified at least.
Metadata
Metadata
Assignees
Labels
for: external-projectNeeds a fix in external projectNeeds a fix in external projectin: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancementA general enhancement