Skip to content

Commit

Permalink
fixed parsing 200 status with empty body
Browse files Browse the repository at this point in the history
  • Loading branch information
Iulian Masar committed Feb 14, 2025
1 parent 8c5831b commit f7ccc6c
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/main/java/com/mangopay/core/RestTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,12 @@ private <T extends Dto, U extends Dto> T doRequest(Class<T> classOfT, String ide

this.readResponseHeaders(connection);

response = castResponseToEntity(classOfT, JsonParser.parseString(responseString).getAsJsonObject());
// some endpoints return 200 with empty body
if (!responseString.isEmpty()) {
response = castResponseToEntity(classOfT, JsonParser.parseString(responseString).getAsJsonObject());
if (this.debugMode) logger.info("Response object: {}", response.toString());
}

if (this.debugMode) logger.info("Response object: {}", response.toString());
}

this.checkResponseCode(responseString);
Expand Down Expand Up @@ -621,20 +624,22 @@ private <T extends Dto> List<T> doRequestList(Class<T[]> classOfT, Class<T> clas
}

if (responseCodeIsSuccessful() && responseCode != 204) {

this.readResponseHeaders(connection);

JsonArray ja = JsonParser.parseString(responseString).getAsJsonArray();
// some endpoints return 200 with empty body
if (!responseString.isEmpty()) {
JsonArray ja = JsonParser.parseString(responseString).getAsJsonArray();

for (int x = 0; x < ja.size(); x++) {
JsonObject jo = ja.get(x).getAsJsonObject();
T toAdd = castResponseToEntity(classOfTItem, jo);
response.add(toAdd);
}
for (int x = 0; x < ja.size(); x++) {
JsonObject jo = ja.get(x).getAsJsonObject();
T toAdd = castResponseToEntity(classOfTItem, jo);
response.add(toAdd);
}

if (this.debugMode) {
logger.info("Response object: {}", response.toString());
logger.info("Elements count: {}", response.size());
if (this.debugMode) {
logger.info("Response object: {}", response.toString());
logger.info("Elements count: {}", response.size());
}
}
}

Expand Down

0 comments on commit f7ccc6c

Please sign in to comment.