List of usage examples for com.google.gson JsonElement getAsJsonObject
public JsonObject getAsJsonObject()
From source file:com.cn.controller.OrderController.java
/** * APP??/*from w ww . ja v a2 s . c om*/ * * @param info * @param username * @param cardNum * @param orderId * @param isGuanShu * @param jsonData * @return */ public int addStationData(StationInfo info, String username, String cardNum, int orderId, int isGuanShu, String jsonData) { DatabaseOpt opt; Connection conn = null; CallableStatement statement = null; CallableStatement updateMarkColor = null; int uploadProductInfoParamsCount = 0; int updateProductInfoParamsCount = 0; int result = -1; try { JsonArray array = new JsonParser().parse(jsonData).getAsJsonArray(); String sql = "{call " + info.getAddDataPro() + "(?, ?, ?, ?"; for (JsonElement element : array) { if (!Units.isStrInArray(element.getAsJsonObject().get("fieldName").getAsString(), productInfoField)) { sql += ", ?"; } else { uploadProductInfoParamsCount++; } } if (isGuanShu == 1) { sql += ", ?)}"; } if (isGuanShu == 0) { sql += ", ?, ?)}"; } System.out.println("sql:" + sql + ",isGuanShu:" + isGuanShu + ",cardNum:" + cardNum); opt = new DatabaseOpt(); conn = opt.getConnect(); statement = conn.prepareCall(sql); statement.setString("cardNum", cardNum); statement.setString("username", username); statement.setInt("orderid", orderId); statement.setInt("isGuanShu", isGuanShu); statement.registerOutParameter("result", Types.INTEGER); if (isGuanShu == 0) { statement.setInt("GuanShuSerial", 0); } for (JsonElement element : array) { JsonObject object = element.getAsJsonObject(); if (Units.isStrInArray(object.get("fieldName").getAsString(), productInfoField)) { if (null != updateMarkColor) { updateMarkColor.setString(object.get("fieldName").getAsString(), object.get("fieldValue").getAsString()); } else { String sql1 = "{call [tbUpdateMarkColor](?"; for (int i = 0; i < productInfoField.length; i++) { sql1 += ", ?"; } sql1 += ")}"; updateMarkColor = conn.prepareCall(sql1); updateMarkColor.setInt("orderId", orderId); for (String field : productInfoField) { updateMarkColor.setString(field, null); } updateMarkColor.setString(object.get("fieldName").getAsString(), object.get("fieldValue").getAsString()); } updateProductInfoParamsCount++; if (updateProductInfoParamsCount == uploadProductInfoParamsCount) { updateMarkColor.executeUpdate(); } continue; } /* if (object.get("fieldName").getAsString().equals("MarkColorValue")) { updateMarkColorParamsCount++; if (null != updateMarkColor) { updateMarkColor.setString("MarkColorValue", object.get("fieldValue").getAsString()); if (updateMarkColorParamsCount == 2) { updateMarkColor.executeUpdate(); } } else { updateMarkColor = conn.prepareCall("{call [tbUpdateMarkColor](?, ?, ?, ?)}"); updateMarkColor.setInt("orderId", orderId); updateMarkColor.setString("MarkColorValue", object.get("fieldValue").getAsString()); } continue; } if (object.get("fieldName").getAsString().equals("MarkColorValue1")) { updateMarkColorParamsCount++; if (null != updateMarkColor) { updateMarkColor.setString("MarkColorValue1", object.get("fieldValue").getAsString()); if (updateMarkColorParamsCount == 2) { updateMarkColor.executeUpdate(); } } else { updateMarkColor = conn.prepareCall("{call [tbUpdateMarkColor](?, ?, ?, ?)}"); updateMarkColor.setInt("orderId", orderId); updateMarkColor.setString("MarkColorValue1", object.get("fieldValue").getAsString()); } continue; } */ switch (object.get("fieldType").getAsInt()) { case 1: { statement.setInt(object.get("fieldName").getAsString(), object.get("fieldValue").getAsInt()); break; } case 2: { statement.setFloat(object.get("fieldName").getAsString(), object.get("fieldValue").getAsFloat()); break; } case 3: { statement.setString(object.get("fieldName").getAsString(), object.get("fieldValue").getAsString()); break; } case 4: { if (object.get("fieldValue").getAsBoolean()) { statement.setString(object.get("fieldName").getAsString(), "true"); } else { statement.setString(object.get("fieldName").getAsString(), "false"); } break; } } } statement.executeUpdate(); result = statement.getInt("result"); System.out.println("result:" + result); } catch (SQLException ex) { logger.error("??", ex); } finally { try { if (updateMarkColor != null) { updateMarkColor.close(); } if (statement != null) { statement.close(); } if (conn != null) { conn.close(); } } catch (SQLException ex) { logger.error("?", ex); } } return result; }
From source file:com.codereligion.bugsnag.logback.resource.TabVOSerializer.java
License:Apache License
private void filterJsonElement(final JsonElement jsonElement) { if (jsonElement.isJsonArray()) { filterJsonArray(jsonElement.getAsJsonArray()); } else if (jsonElement.isJsonObject()) { filterJsonObject(jsonElement.getAsJsonObject()); }// w ww . j a v a 2 s . c o m }
From source file:com.cognifide.aet.job.common.collectors.accessibility.AccessibilityIssueDeserializer.java
License:Apache License
@Override public AccessibilityIssue deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext jsonDeserializationContext) { JsonObject jo = json.getAsJsonObject(); String message = jo.get("message").getAsString(); String code = jo.get("code").getAsString(); IssueType type = IssueType.byValue(jo.get("type").getAsString()); JsonElement jsonElement = jo.get("elementString"); String elementString = NULL_ELEMENT_STRING; if (jsonElement != null) { elementString = jsonElement.getAsString(); }//from w w w .ja va 2s . co m String elementStringAbbrv = StringEscapeUtils.escapeHtml4(elementString); elementStringAbbrv = StringUtils.abbreviateMiddle(elementStringAbbrv, "...", MAX_PRE_STRING_LENGTH); return new AccessibilityIssue(type, message, code, elementString, elementStringAbbrv); }
From source file:com.cognifide.aet.job.common.comparators.w3chtml5.parser.W3cHtml5IssueDeserializer.java
License:Apache License
@Override public W3cHtml5Issue deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext jsonDeserializationContext) { JsonObject jo = json.getAsJsonObject(); String type = getAsString(jo, TYPE); String subtype = getAsString(jo, SUBTYPE); String message = getAsString(jo, MESSAGE); String extract = getAsString(jo, EXTRACT); int lastLine = getAsInt(jo, LAST_LINE); int lastColumn = getAsInt(jo, LAST_COLUMN); int hiliteStart = getAsInt(jo, HILITE_START); int hiliteLength = getAsInt(jo, HILITE_LENGTH); String beforeHilite = StringUtils.substring(extract, 0, hiliteStart); String hilite = StringUtils.substring(extract, hiliteStart, hiliteStart + hiliteLength); String afterHilite = StringUtils.substring(extract, hiliteStart + hiliteLength); // problem with left and right double quotation mark not being displayed correctly message = StringUtils.replaceEach(message, new String[] { "\u00E2\u20AC\u015B", "\u00E2\u20AC" + "\u0165" }, new String[] { "", "" }); // messages often contain HTML entities, escaping them, so they are displayed literally message = StringEscapeUtils.escapeHtml4(message); return new W3cHtml5Issue(lastLine, lastColumn, message, beforeHilite, afterHilite, hilite, null, W3cHtml5IssueType.getType(type, subtype)); }
From source file:com.cognifide.qa.bb.aem.AemInstanceDetails.java
License:Apache License
private DefaultArtifactVersion parseVersionInfo(String versionInfo) { Gson gson = new Gson(); JsonElement element = gson.fromJson(versionInfo, JsonElement.class); JsonObject jsonObj = element.getAsJsonObject(); aemVersion = new DefaultArtifactVersion(jsonObj.get("version").getAsString()); return aemVersion; }
From source file:com.collaborne.build.txgh.GitHubServlet.java
License:Apache License
protected void processPushEvent(TXGHProject project, JsonObject payloadObject) throws IOException { // FIXME: Match up with the 'branch' in the TXGHProject if (payloadObject.get("ref").getAsString().equals("refs/heads/master")) { GitHubProject gitHubProject = project.getGitHubProject(); GitHubApi gitHubApi = gitHubProject.getGitHubApi(); Repository gitHubRepository = gitHubApi.getRepository(); TransifexProject transifexProject = project.getTransifexProject(); Map<String, TransifexResource> sourceFileMap = transifexProject.getSourceFileMap(); Map<String, TransifexResource> updatedTransifexResourceMap = new LinkedHashMap<>(); for (JsonElement commitElement : payloadObject.get("commits").getAsJsonArray()) { JsonObject commitObject = commitElement.getAsJsonObject(); for (JsonElement modified : commitObject.get("modified").getAsJsonArray()) { String modifiedSourceFile = modified.getAsString(); LOGGER.debug("Modified source file: " + modifiedSourceFile); if (sourceFileMap.containsKey(modifiedSourceFile)) { LOGGER.debug("Watched source file has been found: " + modifiedSourceFile); updatedTransifexResourceMap.put(commitObject.get("id").getAsString(), sourceFileMap.get(modifiedSourceFile)); }/*from w ww . j av a 2s . c o m*/ } } for (Entry<String, TransifexResource> entry : updatedTransifexResourceMap.entrySet()) { String sourceFile = entry.getValue().getSourceFile(); LOGGER.debug("Modified source file (watched): " + sourceFile); String treeSha = gitHubApi.getCommitTreeSha(gitHubRepository, entry.getKey()); Tree tree = gitHubApi.getTree(gitHubRepository, treeSha); for (TreeEntry file : tree.getTree()) { LOGGER.debug("Repository file: " + file.getPath()); if (sourceFile.equals(file.getPath())) { transifexProject.getTransifexApi().update(entry.getValue(), gitHubApi.getFileContent(gitHubRepository, file.getSha())); break; } } } } }
From source file:com.collaide.fileuploader.requests.notifications.RepoItemsNotificationRequest.java
public void notificationWithListener(int userId, long timestamp, RepoItemListener[] listeners) { for (JsonElement notificationElement : getJsonNotifications(userId, timestamp)) { try {/* w w w .j a v a 2s.co m*/ Class notification = getClassFromString( notificationElement.getAsJsonObject().get("type").getAsString()); for (RepoItemListener listener : listeners) { new CallListenerMethodThread(notification, listener, notificationElement.toString()).start(); } } catch (ClassNotFoundException ex) { logger.error("Notification cannot be found: " + ex); } } }
From source file:com.collaide.fileuploader.requests.notifications.RepoItemsNotificationRequest.java
/** * <br/>//from w w w.j a v a 2 s . c om * get the notifications between the time passed in params and now * * @param userId * @param timestamp * @return */ public NotificationsMap getNotifications(int userId, long timestamp) { NotificationsMap notificationsMap = new NotificationsMap(); for (JsonElement notificationElement : getJsonNotifications(userId, timestamp)) { try { Class notification = getClassFromString( notificationElement.getAsJsonObject().get("type").getAsString()); logger.debug("json: " + notificationElement.toString()); notificationsMap.addNotification(Model.getJson(notification, notificationElement.toString())); } catch (ClassNotFoundException ex) { logger.error("Notification cannot be found: " + ex); return null; } } return notificationsMap; }
From source file:com.collaide.fileuploader.requests.repository.RepositoryRequest.java
/** * Get a list of items(files or folders) from the server * * @param response The Request to execute * @return a class <code>Repository</code> containing a list of files and a * list of folders// w w w .j av a2 s.c om */ private Repository getRepository(JsonElement json) { Repository repo = new Repository(); for (JsonElement jsonElement : json.getAsJsonArray()) { JsonObject repoItem = jsonElement.getAsJsonObject(); if (repoItem.get("is_folder").getAsBoolean()) { repo.getServerFolders().put(repoItem.get("name").getAsString(), gson.fromJson(repoItem, RepoFolder.class)); } else { repo.getServerFiles().put(repoItem.get("md5").getAsString() + repoItem.get("name").getAsString(), gson.fromJson(repoItem, RepoFile.class)); } } return repo; }
From source file:com.collective.celos.ci.testing.fixtures.compare.json.JsonElementConstructor.java
License:Apache License
private JsonElement deepCopy(String path, JsonElement el, Set<String> ignorePaths) { if (el.isJsonArray()) { return deepCopyJsonArray(path, el.getAsJsonArray(), ignorePaths); }//www.jav a 2 s . c om if (el.isJsonObject()) { return deepCopyJsonObject(path, el.getAsJsonObject(), ignorePaths); } if (el.isJsonPrimitive() || el.isJsonNull()) { return el; } throw new IllegalStateException( "JSONElement should be either Array, Object, Primitive or Null. So you cannot get here"); }