Skip to content
This repository has been archived by the owner on Jul 29, 2023. It is now read-only.

Commit

Permalink
Merge pull request #97 from miurahr/topic/miurahr/api-client-check-json
Browse files Browse the repository at this point in the history
ApiClient: check json parse result
  • Loading branch information
miurahr authored Jun 4, 2022
2 parents 9368b0b + 3a8c7fd commit 864e1e1
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/main/java/tokyo/northside/omegat/textra/TextraApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,14 @@ public String executeTranslation(final TextraOptions options, final String text)
throw new Exception(String.format("Get response: %d", respStatus));
}

String result;
ObjectMapper mapper = new ObjectMapper();
try (BufferedInputStream bis = new BufferedInputStream(respBodyStream)) {
String rsp = IOUtils.toString(bis, StandardCharsets.UTF_8);
ObjectMapper mapper = new ObjectMapper();
JsonNode jobj = mapper.readTree(rsp);
JsonNode resultset = jobj.get("resultset");
result = resultset.get("result").get("text").asText();
ResultSet resultSet = mapper.readValue(bis, ResultSet.class);
return resultSet.result.text;
} catch (IOException ex) {
Log.log(ex);
return null;
}
return result;
}

private static String getAccessUrl(final TextraOptions options) {
Expand All @@ -211,4 +207,12 @@ private static String getAccessUrl(final TextraOptions options) {
}
return apiUrl;
}

static class ResultSet {
public Result result;
}

static class Result {
public String text;
}
}

0 comments on commit 864e1e1

Please sign in to comment.