i have a code like below
HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.CONTENT_TYPE, "application/json;charset=EUC-KR");
headers.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);
RestTemplate restTemplate = RestUtils.getRestTemplate(readTimeout);
Map response = restTemplate.exchange(url, HttpMethod.POST, new HttpEntity<>(params, headers), Map.class).getBody();
````
Recently i updated spring 4.3* to 5.3*. After then it fail's to send request. Because, MappingJackson2HttpMessageConverter enforce encoding like UTF**(unicode)
```java
@Override
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;
}
}
AtomicReference<Throwable> causeRef = new AtomicReference<>();
if (this.objectMapper.canSerialize(clazz, causeRef)) {
return true;
}
logWarningIfNecessary(clazz, causeRef.get());
return false;
}
````
```java
package com.fasterxml.jackson.core;
/**
* Enumeration that defines legal encodings that can be used
* for JSON content, based on list of allowed encodings from
* <a href="http://www.ietf.org/rfc/rfc4627.txt">JSON specification</a>.
*<p>
* Note: if application want to explicitly disregard Encoding
* limitations (to read in JSON encoded using an encoding not
* listed as allowed), they can use {@link java.io.Reader} /
* {@link java.io.Writer} instances as input
*/
public enum JsonEncoding {
UTF8("UTF-8", false, 8), // N/A for big-endian, really
UTF16_BE("UTF-16BE", true, 16),
UTF16_LE("UTF-16LE", false, 16),
UTF32_BE("UTF-32BE", true, 32),
UTF32_LE("UTF-32LE", false, 32)
;
.......
how can i use 'euc-kr' as charset instead.
Comment From: poutsma
According to the relevant specifications, JSON should be written in UTF-8, though UTF-16 or UTF-32 can also be used. Therefore, Jackson (and the Spring components that depend on Jackson) do not support writing non-UTF JSON.
In earlier versions of Spring Framework, the message converters ignored the character encoding completely, and wrote UTF-8 even though the Content-Type indicated otherwise. See https://github.com/spring-projects/spring-framework/issues/25076