fix: java apache httpclient should support UTF-8 by default (#17395)

* fix(java): apache-httpclient serialization error

fixes following related issue:
https://github.com/OpenAPITools/openapi-generator/issues/12797

* docs(java): update samples and docs
This commit is contained in:
renaud-twd
2023-12-14 15:01:10 -10:00
committed by GitHub
parent 0062d1c8da
commit a9179e95dd
3 changed files with 6 additions and 3 deletions

View File

@@ -67,6 +67,7 @@ import java.io.InputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
@@ -796,7 +797,7 @@ public class ApiClient extends JavaTimeFormatter {
String mimeType = contentType.getMimeType();
if (isJsonMime(mimeType)) {
try {
return new StringEntity(objectMapper.writeValueAsString(obj), contentType);
return new StringEntity(objectMapper.writeValueAsString(obj), contentType.withCharset(StandardCharsets.UTF_8));
} catch (JsonProcessingException e) {
throw new ApiException(e);
}