Skip to content

Commit

Permalink
fix: java apache httpclient should support UTF-8 by default (OpenAPIT…
Browse files Browse the repository at this point in the history
…ools#17395)

* fix(java): apache-httpclient serialization error

fixes following related issue:
OpenAPITools#12797

* docs(java): update samples and docs
  • Loading branch information
renaud-twd authored Dec 15, 2023
1 parent 0062d1c commit a9179e9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,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;
Expand Down Expand Up @@ -785,7 +786,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
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;
Expand Down Expand Up @@ -703,7 +704,7 @@ public HttpEntity serialize(Object obj, Map<String, Object> formParams, ContentT
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
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;
Expand Down Expand Up @@ -796,7 +797,7 @@ public HttpEntity serialize(Object obj, Map<String, Object> formParams, ContentT
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);
}
Expand Down

0 comments on commit a9179e9

Please sign in to comment.