List of usage examples for com.google.gson JsonArray add
public void add(JsonElement element)
From source file:ca.paullalonde.gocd.sns_plugin.executors.NotificationInterestedInExecutor.java
License:Apache License
@Override public GoPluginApiResponse execute() throws Exception { JsonObject jsonObject = new JsonObject(); JsonArray notifications = new JsonArray(); notifications.add(REQUEST_STAGE_STATUS.requestName()); jsonObject.add("notifications", notifications); DefaultGoPluginApiResponse defaultGoPluginApiResponse = new DefaultGoPluginApiResponse(200); defaultGoPluginApiResponse.setResponseBody(GSON.toJson(jsonObject)); return defaultGoPluginApiResponse; }
From source file:ca.ualberta.cs.unter.util.GeoPointConverter.java
License:Apache License
@Override public JsonElement serialize(GeoPoint src, Type srcType, JsonSerializationContext context) { JsonArray array = new JsonArray(); array.add(context.serialize(src.getLongitudeE6() / 1E6, Double.class)); array.add(context.serialize(src.getLatitudeE6() / 1E6, Double.class)); return array; }
From source file:ca.uhn.fhir.jpa.util.jsonpatch.CopyOperation.java
License:Apache License
@Override public JsonElement apply(JsonElement original) { JsonElement result = duplicate(original); JsonElement item = path.head().navigate(result); JsonElement data = mySourcePath.head().navigate(original); if (item.isJsonObject()) { item.getAsJsonObject().add(path.tail(), data); } else if (item.isJsonArray()) { JsonArray array = item.getAsJsonArray(); int index = (path.tail().equals("-")) ? array.size() : Integer.valueOf(path.tail()); List<JsonElement> temp = new ArrayList<JsonElement>(); Iterator<JsonElement> iter = array.iterator(); while (iter.hasNext()) { JsonElement stuff = iter.next(); iter.remove();// w ww . jav a2 s . c om temp.add(stuff); } temp.add(index, data); for (JsonElement stuff : temp) { array.add(stuff); } } return result; }
From source file:cashPR.GetCashPaymentHeader.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//w ww . j a v a2s.co m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Connection dataConnection = null; final JsonObject jResultObj = new JsonObject(); final String from_date = request.getParameter("from_date"); final String to_date = request.getParameter("to_date"); final String v_type = request.getParameter("v_type"); final String branch_cd = request.getParameter("branch_cd"); if (dataConnection == null) { dataConnection = helper.getConnMpAdmin(); } if (dataConnection != null) { try { String sql = "select c.AC_CD,c.REF_NO,VDATE,a.FNAME,c1.BAL,c1.REMARK,c.branch_cd from CPRHD c left join CPRDT c1 on c.REF_NO=c1.REF_NO" + " left join ACNTMST a on c.AC_CD=a.AC_CD where VDATE>=? and VDATE<=? and CTYPE=? "; if (!branch_cd.equalsIgnoreCase("0")) { sql += " and branch_cd=" + branch_cd; } sql += " order by VDATE,ref_no"; PreparedStatement pstLocal = dataConnection.prepareStatement(sql); pstLocal.setString(1, from_date); pstLocal.setString(2, to_date); pstLocal.setString(3, v_type); ResultSet rsLocal = pstLocal.executeQuery(); JsonArray array = new JsonArray(); while (rsLocal.next()) { JsonObject object = new JsonObject(); object.addProperty("REF_NO", rsLocal.getString("REF_NO")); object.addProperty("VDATE", rsLocal.getString("VDATE")); object.addProperty("FNAME", rsLocal.getString("FNAME")); object.addProperty("BAL", rsLocal.getString("BAL")); object.addProperty("REMARK", rsLocal.getString("REMARK")); object.addProperty("AC_CD", rsLocal.getString("AC_CD")); object.addProperty("BRANCH_CD", rsLocal.getString("BRANCH_CD")); array.add(object); } // response.getWriter().print(array.toString()); jResultObj.addProperty("result", 1); jResultObj.addProperty("Cause", "success"); jResultObj.add("data", array); } catch (SQLNonTransientConnectionException ex1) { jResultObj.addProperty("result", -1); jResultObj.addProperty("Cause", "Server is down"); } catch (SQLException ex) { jResultObj.addProperty("result", -1); jResultObj.addProperty("Cause", ex.getMessage()); } } response.getWriter().print(jResultObj); }
From source file:catalog.CloudantUtil.java
License:Apache License
public static JsonArray createDocumentArray(int numDocs) { // Array of docs for bulk JsonArray bulkDocs = new JsonArray(); for (int i = 1; i <= numDocs; i++) { JsonObject cloudantDoc = new JsonObject(); String now = new Date().toString(); cloudantDoc.addProperty("_id", CloudantUtil.DOC_ID + i); cloudantDoc.addProperty("date", now); bulkDocs.add(cloudantDoc); }//ww w .ja v a 2 s . c o m return bulkDocs; }
From source file:ccm.pay2spawn.configurator.Configurator.java
License:Open Source License
private void setupListeners() { typeList.addMouseListener(new MouseAdapter() { @Override/*from w w w .j a va2 s . co m*/ public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { TypeRegistry.getByName(typeList.getSelectedValue()).openNewGui(-1, new JsonObject()); } } }); rewards.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { int id = rewards.getSelectedIndex(); TypeRegistry.getByName(rewards.getSelectedValue()).openNewGui(id, rewardData.get(id).getAsJsonObject().getAsJsonObject("data")); } } }); rewards.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { deleteSelectedRewardButton.setEnabled(!rewards.isSelectionEmpty()); duplicateSelectedRewardButton.setEnabled(!rewards.isSelectionEmpty()); } }); helpMeWithRandomizationButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Help.init(); } }); mainTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { currentlyEditingID = mainTable.getSelectedRow(); currentlyEditingData = rootArray.get(currentlyEditingID).getAsJsonObject(); if (currentlyEditingData.has("rewards")) rewardData = JsonNBTHelper.cloneJSON(currentlyEditingData.getAsJsonArray("rewards")) .getAsJsonArray(); else rewardData = new JsonArray(); rewards.updateUI(); rewards.clearSelection(); typeList.clearSelection(); saveOverOldGroupButton.setEnabled(true); removeGroupButton.setEnabled(true); tabbedPane1.setSelectedIndex(1); nameField.setText(currentlyEditingData.getAsJsonPrimitive(COLUMN_KEYS[0]).getAsString()); amountField.setText(currentlyEditingData.getAsJsonPrimitive(COLUMN_KEYS[1]).getAsString()); messageField.setText(currentlyEditingData.getAsJsonPrimitive(COLUMN_KEYS[2]).getAsString()); countdownTextField.setText(currentlyEditingData.has(COLUMN_KEYS[3]) ? currentlyEditingData.getAsJsonPrimitive(COLUMN_KEYS[3]).getAsString() : ""); } } }); clearButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { clear(); } }); saveOverOldGroupButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (saveEdits()) { JsonArray newRoot = new JsonArray(); for (int i = 0; i < rootArray.size(); i++) if (i != currentlyEditingID) newRoot.add(rootArray.get(i)); rootArray = newRoot; rootArray.add(currentlyEditingData); mainTable.updateUI(); saveMainJsonToFile(); ColumnsAutoSizer.sizeColumnsToFit(mainTable, 20); } } }); saveAsNewGroupButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (saveEdits()) { rootArray.add(currentlyEditingData); currentlyEditingID = rootArray.size() - 1; saveOverOldGroupButton.setEnabled(true); removeGroupButton.setEnabled(true); mainTable.updateUI(); saveMainJsonToFile(); ColumnsAutoSizer.sizeColumnsToFit(mainTable, 20); } } }); removeGroupButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JsonArray newRoot = new JsonArray(); for (int i = 0; i < rootArray.size(); i++) if (i != currentlyEditingID) newRoot.add(rootArray.get(i)); rootArray = newRoot; clear(); tabbedPane1.setSelectedIndex(0); saveMainJsonToFile(); } }); duplicateSelectedRewardButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int toDuplicate = rewards.getSelectedIndex(); rewardData.add(JsonNBTHelper.cloneJSON(rewardData.get(toDuplicate))); rewards.updateUI(); } }); deleteSelectedRewardButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int toRemove = rewards.getSelectedIndex(); JsonArray newRewardData = new JsonArray(); for (int i = 0; i < rewardData.size(); i++) if (i != toRemove) newRewardData.add(rewardData.get(i)); rewardData = newRewardData; rewards.clearSelection(); rewards.updateUI(); } }); makeNiceHtmlPageButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { HTMLGenerator.generate(); } catch (IOException e1) { e1.printStackTrace(); } } }); }
From source file:ccm.pay2spawn.permissions.Group.java
License:Open Source License
public JsonElement toJson() { JsonObject root = new JsonObject(); root.addProperty("name", getName()); root.addProperty("parent", getParent()); JsonArray nodes = new JsonArray(); for (Node node : this.nodes) nodes.add(new JsonPrimitive(node.toString())); root.add("nodes", nodes); return root;/* w w w.j a v a 2s . com*/ }
From source file:ccm.pay2spawn.permissions.PermissionsDB.java
License:Open Source License
public void save() { try {// w w w .ja v a 2 s. c o m File file = getFile(); if (!file.exists()) //noinspection ResultOfMethodCallIgnored file.createNewFile(); JsonObject rootObject = new JsonObject(); JsonArray players = new JsonArray(); for (Player player : playerDB.values()) players.add(player.toJson()); rootObject.add("players", players); JsonArray groups = new JsonArray(); for (Group group : groupDB.values()) groups.add(group.toJson()); rootObject.add("groups", groups); BufferedWriter bw = new BufferedWriter(new FileWriter(file)); bw.write(GSON.toJson(rootObject)); bw.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:ccm.pay2spawn.permissions.Player.java
License:Open Source License
public JsonElement toJson() { JsonObject root = new JsonObject(); root.addProperty("name", getName()); JsonArray groups = new JsonArray(); for (String group : this.getGroups()) groups.add(new JsonPrimitive(group)); root.add("groups", groups); JsonArray nodes = new JsonArray(); for (Node node : this.overrideNodes) nodes.add(new JsonPrimitive(node.toString())); root.add("overrides", nodes); return root;/*w w w.j a va 2s . com*/ }
From source file:ccm.pay2spawn.random.RndColors.java
License:Open Source License
@Override public String solverRandom(int type, String value) { Matcher mRGB = PATTERN.matcher(value); if (type == INT_ARRAY) { JsonArray colors = new JsonArray(); mRGB.find();/*ww w . j av a 2s . c om*/ for (int i = 0; i < Integer.parseInt(mRGB.group(1)); i++) colors.add(new JsonPrimitive( (RANDOM.nextInt(200) << 16) + (RANDOM.nextInt(200) << 8) + RANDOM.nextInt(200))); return mRGB.replaceFirst(colors.toString()); } else { return mRGB.replaceFirst( "" + ((RANDOM.nextInt(200) << 16) + (RANDOM.nextInt(200) << 8) + RANDOM.nextInt(200))); } }