mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-20 10:57:10 +00:00
[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:
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user