[java][okhttp-gson] fix: JSON deserialization fallback for String return types (#22498)

* Use String-based JSON deserialize method with fallback for String return types

* Regenerate samples
This commit is contained in:
Kevin Lin
2025-12-10 22:47:48 -08:00
committed by GitHub
parent 8f8001ea1a
commit 7ccd039a7b
16 changed files with 176 additions and 16 deletions

View File

@@ -972,7 +972,17 @@ public class ApiClient {
}
try {
if (isJsonMime(contentType)) {
return JSON.deserialize(respBody.byteStream(), returnType);
if (returnType.equals(String.class)) {
String respBodyString = respBody.string();
if (respBodyString.isEmpty()) {
return null;
}
// Use String-based deserialize for String return type with fallback
return JSON.deserialize(respBodyString, returnType);
} else {
// Use InputStream-based deserialize which supports responses > 2GB
return JSON.deserialize(respBody.byteStream(), returnType);
}
} else if (returnType.equals(String.class)) {
String respBodyString = respBody.string();
if (respBodyString.isEmpty()) {