Source:
<code>public HttpRequestBase formatRequest() { URIBuilder uriBuilder = getRepository().getURIBuilder(fAuthIsRequired); Gson gson = new Gson(); String json = null; URI uri = null; try { String path = new StringBuilder(uriBuilder.getPath()).append("/changes/") .append(getId()) .append("/revisions/").append(getRevision()) .append("/drafts") .toString(); uriBuilder.setPath(path); uri = new URI(URIUtil.toUnencodedString(uriBuilder.build())); } catch (URISyntaxException e) { EGerritCorePlugin.logError("URI syntax exception", e); } HttpPut httpPut = new HttpPut(uri); <START> JsonObject jsonCommentInput = new JsonObject(); jsonCommentInput.addProperty("id", fCommentInfo.getId()); jsonCommentInput.addProperty("inReplyTo", fCommentInfo.getInReplyTo()); jsonCommentInput.addProperty("line", fCommentInfo.getLine()); jsonCommentInput.addProperty("message", fCommentInfo.getMessage()); jsonCommentInput.addProperty("path", fCommentInfo.getPath()); json = gson.toJson(fCommentInfo.getRange()); if (json != null && json.compareTo("null") != 0) { jsonCommentInput.addProperty("range", json); } jsonCommentInput.addProperty("side", fCommentInfo.getSide()); if (json != null && json.compareTo("null") != 0) { json = gson.toJson(fCommentInfo.getAuthor()); jsonCommentInput.addProperty("author", json); } StringEntity input = null; try { input = new StringEntity(jsonCommentInput.toString()); } catch (UnsupportedEncodingException e) { EGerritCorePlugin.logError("URI error encoding CommentInfo", e); } <END> input.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); httpPut.setEntity(input); return httpPut; }</code><technical_language>investigate if c a jsonElement a jsonObject validation method apache provides</technical_language>

Target:
public HttpRequestBase formatRequest() { URIBuilder uriBuilder = getRepository().getURIBuilder(fAuthIsRequired); Gson gson = new Gson(); String json = null; URI uri = null; try { String path = new StringBuilder(uriBuilder.getPath()).append("/changes/") .append(getId()) .append("/revisions/").append(getRevision()) .append("/drafts") .toString(); uriBuilder.setPath(path); uri = new URI(URIUtil.toUnencodedString(uriBuilder.build())); } catch (URISyntaxException e) { EGerritCorePlugin.logError("URI syntax exception", e); } HttpPut httpPut = new HttpPut(uri); JsonObject jsonCommentInput = new JsonObject(); jsonCommentInput.addProperty("id", fCommentInfo.getId()); jsonCommentInput.addProperty("inReplyTo", fCommentInfo.getInReplyTo()); jsonCommentInput.addProperty("line", fCommentInfo.getLine()); jsonCommentInput.addProperty("message", fCommentInfo.getMessage()); jsonCommentInput.addProperty("path", fCommentInfo.getPath()); json = gson.toJson(fCommentInfo.getRange()); if (json != null && json.compareTo("null") != 0) { jsonCommentInput.addProperty("range", json); } jsonCommentInput.addProperty("side", fCommentInfo.getSide()); if (json != null && json.compareTo("null") != 0) { json = gson.toJson(fCommentInfo.getAuthor()); jsonCommentInput.addProperty("author", json); } StringEntity input = null; try { input = new StringEntity(jsonCommentInput.toString()); } catch (UnsupportedEncodingException e) { EGerritCorePlugin.logError("URI error encoding CommentInfo", e); } input.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, GerritCommand.JSON_HEADER)); httpPut.setEntity(input); return httpPut; }