List of usage examples for com.google.gson JsonArray JsonArray
public JsonArray()
From source file:arces.unibo.SEPA.commons.SPARQL.BindingsResults.java
License:Open Source License
public BindingsResults(BindingsResults newBindings) { results = new JsonObject(); JsonObject vars = new JsonObject(); JsonArray varArray = new JsonArray(); if (newBindings != null) for (String var : newBindings.getVariables()) { varArray.add(var); }// w w w . j av a 2 s . co m vars.add("vars", varArray); results.add("head", vars); JsonArray bindingsArray = new JsonArray(); if (newBindings != null) for (Bindings solution : newBindings.getBindings()) bindingsArray.add(solution.toJson()); JsonObject bindings = new JsonObject(); bindings.add("bindings", bindingsArray); results.add("results", bindings); }
From source file:assignment3.Assignment3.java
public static String getJSON() { String output = ""; try {/*from w w w . j av a 2 s .c o m*/ JsonArray arr = new JsonArray(); Connection conn = getConnection(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM students"); while (rs.next()) { JsonObject obj = new JsonObject(); obj.addProperty("id", rs.getInt("id")); obj.addProperty("fName", rs.getString("fName")); obj.addProperty("lName", rs.getString("lName")); obj.addProperty("bio", rs.getString("bio")); arr.add(obj); } output = arr.toString(); conn.close(); } catch (SQLException ex) { output = "SQL Exception Error: " + ex.getMessage(); } return output; }
From source file:assignment3.Assignment3.java
public static String getJSON(int id) { String output = ""; try {/*from w ww . j a v a 2 s . c o m*/ JsonArray arr = new JsonArray(); Connection conn = getConnection(); String query = "SELECT * FROM students WHERE id = ?"; PreparedStatement pstmt = conn.prepareStatement(query); pstmt.setInt(1, id); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { JsonObject obj = new JsonObject(); obj.addProperty("id", rs.getInt("id")); obj.addProperty("fName", rs.getString("fName")); obj.addProperty("lName", rs.getString("lName")); obj.addProperty("bio", rs.getString("bio")); arr.add(obj); } output = arr.toString(); conn.close(); } catch (SQLException ex) { output = "SQL Exception Error: " + ex.getMessage(); } return output; }
From source file:at.ac.tuwien.infosys.jcloudscale.datastore.mapping.type.json.JsonListTypeAdapter.java
License:Apache License
@Override public JsonElement serialize(List<?> object, TypeMetadata<JsonElement> typeMetadata) { JsonArray jsonArray = new JsonArray(); TypeAdapter typeAdapter = typeMetadata.getTypeParameterTypeAdapters().get(0); for (Object item : object) { JsonElement jsonElement = (JsonElement) typeAdapter.serialize(item, typeMetadata); jsonArray.add(jsonElement);//from w w w . j ava 2s . com } return jsonArray; }
From source file:at.tugraz.kmi.medokyservice.fca.util.ImportExport.java
License:Open Source License
private JsonElement domains2JSON() { BlockingDeque<Domain> domains = Database.getInstance().getAll(Domain.class); JsonArray jsD = new JsonArray(); for (Domain d : domains) { IncidenceMatrix mat = d.getMapping(); Map<FCAObject, Set<FCAAttribute>> mapping = mat.getObjects(); JsonObject jso = prepare(d);//w ww . j a v a 2 s. co m JsonObject jsM = new JsonObject(); for (long mId : mat.getItemMetadata().keySet()) { jsM.addProperty(Long.toString(mId), mat.getItemMetadata().get(mId).getId()); } jso.add(SECTION_M, jsM); List<Long> ownerIDs = new LinkedList<Long>(); for (User o : d.getOwners()) { ownerIDs.add(o.getId()); } jso.add(OWNER, gson.toJsonTree(ownerIDs, new TypeToken<List<Long>>() { }.getType())); jso.addProperty(GLOBAL, d.isGlobal()); jso.addProperty(APPROVED, d.isApproved()); JsonObject jsMapping = new JsonObject(); for (FCAObject o : mapping.keySet()) { LinkedList<Long> aIds = new LinkedList<Long>(); for (FCAAttribute a : mapping.get(o)) { aIds.add(a.getId()); } jsMapping.add(Long.toString(o.getId()), gson.toJsonTree(aIds, new TypeToken<List<Long>>() { }.getType())); } jso.add(MAPPING, jsMapping); jsD.add(jso); } return jsD; }
From source file:at.tugraz.kmi.medokyservice.fca.util.ImportExport.java
License:Open Source License
private JsonElement courses2JSON() { BlockingDeque<Course> courses = Database.getInstance().getAll(Course.class); JsonArray jsC = new JsonArray(); for (Course o : courses) { JsonObject jso = prepare(o);/* w ww . j a v a 2s.c o m*/ Set<Domain> domains = o.getDomains(); LinkedList<Long> dIds = new LinkedList<Long>(); for (Domain d : domains) dIds.add(d.getId()); jso.add(SECTION_D, gson.toJsonTree(dIds, new TypeToken<List<Long>>() { }.getType())); jso.addProperty(E_CID, o.getExternalCourseID()); List<Long> participants = new LinkedList<Long>(); for (User u : o.getParticipants()) participants.add(u.getId()); jso.add(PARTICIPANTS, gson.toJsonTree(participants, new TypeToken<List<Long>>() { }.getType())); jsC.add(jso); } return jsC; }
From source file:at.yawk.buycraft.BuycraftApi.java
License:Mozilla Public License
/** * @see #commands(String, String, String) *//*w w w . j av a 2s. c o m*/ default List<Command> commands(Collection<String> players, boolean offlineCommands, int offlineCommandLimit) throws IOException { JsonArray array = new JsonArray(); players.forEach(p -> array.add(new JsonPrimitive(p))); return commands(array.toString(), Boolean.toString(offlineCommands), Integer.toString(offlineCommandLimit)); }
From source file:at.yawk.buycraft.BuycraftApi.java
License:Mozilla Public License
/** * @see #removeCommands(String)//ww w. ja v a 2 s.c om */ default void removeCommands(Collection<Integer> commandIds) throws IOException { JsonArray array = new JsonArray(); commandIds.forEach(i -> array.add(new JsonPrimitive(i))); removeCommands(array.toString()); }
From source file:au.edu.unsw.cse.soc.federatedcloud.cloudRessourceBase.RecommenderAPI.java
License:Open Source License
private JsonObject returnDummyObject() { JsonObject json = new JsonObject(); JsonArray descriptionsJsonArray = new JsonArray(); JsonObject desciption1 = new JsonObject(); desciption1.addProperty("Id", "1"); desciption1.addProperty("Name", "SE-Bucket"); desciption1.addProperty("TargetEnv", "IaaS"); desciption1.addProperty("Deployer", "au.edu.unsw.cse.soc.federatedcloud.deployers.aws.AWSS3Deployer"); descriptionsJsonArray.add(desciption1); JsonObject desciption2 = new JsonObject(); desciption2.addProperty("Id", "2"); desciption2.addProperty("Name", "Rackspace-VM"); desciption2.addProperty("TargetEnv", "IaaS"); desciption2.addProperty("Deployer", "au.edu.unsw.cse.soc.federatedcloud.deployers.rackspace.RackspaceDeployer"); descriptionsJsonArray.add(desciption2); JsonObject desciption3 = new JsonObject(); desciption3.addProperty("Id", "3"); desciption3.addProperty("Name", "GoogleDrive"); desciption3.addProperty("TargetEnv", "SaaS"); desciption3.addProperty("Deployer", "au.edu.unsw.cse.soc.federatedcloud.deployers.GoogleDriveDeployer"); descriptionsJsonArray.add(desciption3); json.add("CloudResourceDescriptions", descriptionsJsonArray); return json;//from w w w.ja v a 2 s . c o m }
From source file:bank.GetBankPaymentHeader.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*ww w. ja v a2s . com*/ * * @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.cheque_no,c.branch_cd from bprhd c left join bprdt 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("CHEQUE_NO", rsLocal.getString("CHEQUE_NO")); object.addProperty("BRANCH_CD", rsLocal.getString("BRANCH_CD")); array.add(object); } 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); }