Source:
private void parseEventParameters(InputStream jsonBody) { Gson gson = new Gson(); Type type = new TypeToken<Map<String, Object>[]>(){}.getType(); BufferedReader reader; try { reader = new BufferedReader(new InputStreamReader(jsonBody, CHARSET_UTF8)); Optional<Map<String, Object>[]> possibleParameters = Optional.ofNullable(gson.fromJson(reader, type)); if (!possibleParameters.isPresent()) { return; } Map<String, Object>[] eventsWithParameters = possibleParameters.get(); IssueEvent[] issueEvents = (IssueEvent[]) response.getBody(); Map<String, String> parameters; for (int i = 0; i < issueEvents.length; i++) { TurboIssueEvent event = new TurboIssueEvent( issueEvents[i].getActor(), IssueEventType.fromString(issueEvents[i].getEvent()), issueEvents[i].getCreatedAt()); switch (event.getType()) { case Renamed: parameters = (Map<String, String>) eventsWithParameters[i].get("rename"); event.setRenamedFrom(parameters.get("from")); event.setRenamedTo(parameters.get("to")); break; case Milestoned: case Demilestoned: parameters = (Map<String, String>) eventsWithParameters[i].get("milestone"); event.setMilestoneTitle(parameters.get("title")); break; case Labeled: case Unlabeled: parameters = (Map<String, String>) eventsWithParameters[i].get("label"); event.setLabelColour(parameters.get("color")); event.setLabelName(parameters.get("name")); break; case Assigned: case Unassigned: Object assigneeMap = eventsWithParameters[i].get("assignee"); String json = new Gson().toJson(assigneeMap); User user = gson.fromJson(json, User.class); event.setAssignedUser(user); break; case Closed: case Reopened: case Locked: case Unlocked: break; case Subscribed: case Merged: case HeadRefDeleted: case HeadRefRestored: case Referenced: case Mentioned: default: } turboIssueEvents.add(event); } } catch (UnsupportedEncodingException e) { logger.error(e.getLocalizedMessage(), e); } }

Target:
private void parseEventParameters(InputStream jsonBody) { Gson gson = new Gson(); Type type = new TypeToken<Map<String, Object>[]>(){}.getType(); BufferedReader reader; try { reader = new BufferedReader(new InputStreamReader(jsonBody, CHARSET_UTF8)); Map<String, Object>[] eventsWithParameters = gson.fromJson(reader, type); if (eventsWithParameters == null) { return; } IssueEvent[] issueEvents = (IssueEvent[]) response.getBody(); Map<String, String> parameters; for (int i = 0; i < issueEvents.length; i++) { TurboIssueEvent event = new TurboIssueEvent( issueEvents[i].getActor(), IssueEventType.fromString(issueEvents[i].getEvent()), issueEvents[i].getCreatedAt()); switch (event.getType()) { case Renamed: parameters = (Map<String, String>) eventsWithParameters[i].get("rename"); event.setRenamedFrom(parameters.get("from")); event.setRenamedTo(parameters.get("to")); break; case Milestoned: case Demilestoned: parameters = (Map<String, String>) eventsWithParameters[i].get("milestone"); event.setMilestoneTitle(parameters.get("title")); break; case Labeled: case Unlabeled: parameters = (Map<String, String>) eventsWithParameters[i].get("label"); event.setLabelColour(parameters.get("color")); event.setLabelName(parameters.get("name")); break; case Assigned: case Unassigned: Object assigneeMap = eventsWithParameters[i].get("assignee"); String json = new Gson().toJson(assigneeMap); User user = gson.fromJson(json, User.class); event.setAssignedUser(user); break; case Closed: case Reopened: case Locked: case Unlocked: break; case Subscribed: case Merged: case HeadRefDeleted: case HeadRefRestored: case Referenced: case Mentioned: default: } turboIssueEvents.add(event); } } catch (UnsupportedEncodingException e) { logger.error(e.getLocalizedMessage(), e); } }