mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-03 08:46:55 +00:00
[JAVA][apache-httpclient] Use `EntityUtils#toString instead of Scanner` (#17998)
``EntityUtils#toString`` automatically selects the correct encoding based on the received request. Scanner currently uses the JVM default encoding, which doesn't always work.
This commit is contained in:
@@ -771,8 +771,7 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
if (mimeType == null || isJsonMime(mimeType)) {
|
||||
// Assume json if no mime type
|
||||
// convert input stream to string
|
||||
java.util.Scanner s = new java.util.Scanner(entity.getContent()).useDelimiter("\\A");
|
||||
String content = (String) (s.hasNext() ? s.next() : "");
|
||||
String content = EntityUtils.toString(entity);
|
||||
|
||||
if ("".equals(content)) { // returns null for empty body
|
||||
return null;
|
||||
@@ -781,8 +780,7 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
return objectMapper.readValue(content, valueType);
|
||||
} else if ("text/plain".equalsIgnoreCase(mimeType)) {
|
||||
// convert input stream to string
|
||||
java.util.Scanner s = new java.util.Scanner(entity.getContent()).useDelimiter("\\A");
|
||||
return (T) (s.hasNext() ? s.next() : "");
|
||||
return (T) EntityUtils.toString(entity);
|
||||
} else {
|
||||
throw new ApiException(
|
||||
"Deserialization for content type '" + mimeType + "' not supported for type '" + valueType + "'",
|
||||
|
||||
Reference in New Issue
Block a user