I'm trying to integrate redmine's API, to read the subject from a specific Issue with the Id, but I'm getting a NullPointerException in issueSubject even if the JSON response is not empty.
`public String getIssueById(){
String issueId = "38480";
String endPoint = "http://www.redmine.org/issues/" + issueId + ".json";
HttpClient httpClient = HttpClientBuilder.create().build();
HttpGet getRequest = new HttpGet(endPoint);
String auth = "admin:admin";
byte[] encodedAuth = Base64.encodeBase64(auth.getBytes());
String authHeader = "Basic " + new String(encodedAuth);
getRequest.setHeader("Authorization", authHeader);
getRequest.addHeader("accept", "application/json");
try {
HttpResponse response = httpClient.execute(getRequest);
HttpEntity entity = response.getEntity();
String responseString = EntityUtils.toString(entity, "UTF-8");
Logger.getLogger(responseString + "valore della response string");
Gson gson = new Gson();
JsonObject jsonObject = gson.fromJson(responseString, JsonObject.class);
String issueSubject = jsonObject.get("issue").getAsJsonObject().get("subject").getAsString();
System.out.println("Issue Subject: " + value);
Logger.getLogger(value + "valore della value string");
} catch (Exception e) {
e.printStackTrace();
}
finally {
return issueSubject ;
}
}
JSON Response: enter image description here
What could be the problem?