mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-07 21:06:11 +00:00
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:
@@ -61,6 +61,7 @@ import java.io.InputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.charset.UnsupportedCharsetException;
|
import java.nio.charset.UnsupportedCharsetException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
@@ -785,7 +786,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
|
|||||||
String mimeType = contentType.getMimeType();
|
String mimeType = contentType.getMimeType();
|
||||||
if (isJsonMime(mimeType)) {
|
if (isJsonMime(mimeType)) {
|
||||||
try {
|
try {
|
||||||
return new StringEntity(objectMapper.writeValueAsString(obj), contentType);
|
return new StringEntity(objectMapper.writeValueAsString(obj), contentType.withCharset(StandardCharsets.UTF_8));
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
throw new ApiException(e);
|
throw new ApiException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ import java.io.InputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.charset.UnsupportedCharsetException;
|
import java.nio.charset.UnsupportedCharsetException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
@@ -703,7 +704,7 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
String mimeType = contentType.getMimeType();
|
String mimeType = contentType.getMimeType();
|
||||||
if (isJsonMime(mimeType)) {
|
if (isJsonMime(mimeType)) {
|
||||||
try {
|
try {
|
||||||
return new StringEntity(objectMapper.writeValueAsString(obj), contentType);
|
return new StringEntity(objectMapper.writeValueAsString(obj), contentType.withCharset(StandardCharsets.UTF_8));
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
throw new ApiException(e);
|
throw new ApiException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ import java.io.InputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.charset.UnsupportedCharsetException;
|
import java.nio.charset.UnsupportedCharsetException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
@@ -796,7 +797,7 @@ public class ApiClient extends JavaTimeFormatter {
|
|||||||
String mimeType = contentType.getMimeType();
|
String mimeType = contentType.getMimeType();
|
||||||
if (isJsonMime(mimeType)) {
|
if (isJsonMime(mimeType)) {
|
||||||
try {
|
try {
|
||||||
return new StringEntity(objectMapper.writeValueAsString(obj), contentType);
|
return new StringEntity(objectMapper.writeValueAsString(obj), contentType.withCharset(StandardCharsets.UTF_8));
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
throw new ApiException(e);
|
throw new ApiException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user