Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java][apache-httpclient] Use EntityUtils#toString instead of Scanner for deserialization #17998

Merged
merged 1 commit into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -853,8 +853,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
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;
Expand All @@ -863,8 +862,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
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 + "'",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,7 @@ public <T> T deserialize(CloseableHttpResponse response, TypeReference<T> valueT
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;
Expand All @@ -781,8 +780,7 @@ public <T> T deserialize(CloseableHttpResponse response, TypeReference<T> valueT
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 + "'",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -864,8 +864,7 @@ public <T> T deserialize(CloseableHttpResponse response, TypeReference<T> valueT
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;
Expand All @@ -874,8 +873,7 @@ public <T> T deserialize(CloseableHttpResponse response, TypeReference<T> valueT
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 + "'",
Expand Down
Loading