List of usage examples for com.google.gson JsonObject JsonObject
JsonObject
From source file:ListAction.java
@Override public void execute(HttpServletRequest request, PrintWriter out, File folder) { try {/* w w w.j av a2s . c o m*/ String type = request.getParameter("type"); JsonArray list = new JsonArray(); switch (type) { case "movie": File[] movies = Service.listAllMovies(folder); for (int i = 0; i < movies.length; i++) { JsonObject m = new JsonObject(); m.addProperty("title", movies[i].getName()); list.add(m); } break; case "series": File[] series = Service.listAllSeries(folder); for (int i = 0; i < series.length; i++) { JsonObject m = new JsonObject(); m.addProperty("title", series[i].getName()); list.add(m); } break; case "episode": String series_title = request.getParameter("series"); folder = new File(folder.getAbsolutePath() + "\\Series\\" + series_title); List<File> episodes = Service.listAllEpisodes(folder); for (File f : episodes) { JsonObject episode = new JsonObject(); String title = f.getName().split(" - ")[0]; episode.addProperty("title", series_title + " - " + title); list.add(episode); } break; } JsonObject container = new JsonObject(); container.add("list", list); Gson gson = new GsonBuilder().setPrettyPrinting().create(); String json = gson.toJson(container); out.println(json); } catch (Exception e) { throw e; } }
From source file:Sleep.java
License:Apache License
public static JsonObject main(JsonObject parm) throws InterruptedException { int sleepTimeInMs = 1; if (parm.has("sleepTimeInMs")) { sleepTimeInMs = parm.getAsJsonPrimitive("sleepTimeInMs").getAsInt(); }/*from ww w . j a v a 2 s . c o m*/ System.out.println("Specified sleep time is " + sleepTimeInMs + " ms."); final String responseText = "Terminated successfully after around " + sleepTimeInMs + " ms."; final JsonObject response = new JsonObject(); response.addProperty("msg", responseText); Thread.sleep(sleepTimeInMs); System.out.println(responseText); return response; }
From source file:EAIJSONConverter.java
License:Open Source License
public void doInvokeMethod(String methodName, SiebelPropertySet input, SiebelPropertySet output) throws SiebelBusinessServiceException { if (methodName.equals("PropSetToJSON")) { JsonObject myJSON = new JsonObject(); myJSON = traversePS(input, myJSON); output.setValue(myJSON.toString()); }/*from ww w.ja v a 2 s . co m*/ if (methodName.equals("JSONToPropSet")) { JsonObject obj = new JsonObject(); obj = new Gson().fromJson(input.getValue(), JsonObject.class); SiebelPropertySet op = new SiebelPropertySet(); output.addChild(JsonObjectToPropertySet(obj, op)); } }
From source file:EAIJSONConverter.java
License:Open Source License
public static SiebelPropertySet JsonObjectToPropertySet(JsonObject obj, SiebelPropertySet ps) { Iterator<Entry<String, JsonElement>> iterator = obj.entrySet().iterator(); SiebelPropertySet child;//from w w w. j a v a 2 s. c o m while (iterator.hasNext()) { JsonArray jsonArray = new JsonArray(); JsonObject jsonObject = new JsonObject(); Map.Entry mapEntry = (Map.Entry) iterator.next(); if (mapEntry != null) { JsonElement jsonelement = (JsonElement) mapEntry.getValue(); if (jsonelement.isJsonArray()) { jsonArray = jsonelement.getAsJsonArray(); child = new SiebelPropertySet(); child.setType("ListOf-" + mapEntry.getKey().toString()); for (int i = 0; i < jsonArray.size(); i++) { if (jsonArray.get(i).isJsonObject() || jsonArray.get(i).isJsonArray()) { SiebelPropertySet temp = new SiebelPropertySet(); temp.setType("" + i); if (jsonArray.get(i).isJsonObject()) child.addChild(JsonObjectToPropertySet(jsonArray.get(i).getAsJsonObject(), temp)); else { JsonObject aux = new JsonObject(); aux.add("" + i, jsonArray.get(i)); child.addChild(JsonObjectToPropertySet(aux, temp)); } } else child.setProperty("" + i, jsonArray.get(i).getAsString()); } ps.addChild(child); } else if (jsonelement.isJsonObject()) { jsonObject = jsonelement.getAsJsonObject(); child = new SiebelPropertySet(); child.setType(mapEntry.getKey().toString()); ps.addChild(JsonObjectToPropertySet(jsonObject, child)); } else { ps.setProperty(mapEntry.getKey().toString(), mapEntry.getValue().toString()); } } } return ps; }
From source file:EAIJSONConverter.java
License:Open Source License
public JsonObject traversePS(SiebelPropertySet ps, JsonObject jObj) { JsonObject siebJSON = new JsonObject(); String propName;// w ww . j av a 2 s .c o m String propVal; propName = ps.getFirstProperty(); while (propName != "") { propVal = ps.getProperty(propName); siebJSON.addProperty(propName, propVal); propName = ps.getNextProperty(); } JsonObject child; for (int i = 0; i < ps.getChildCount(); i++) { child = new JsonObject(); if (ps.getChild(i).getType().startsWith("ListOf-")) { JsonArray ja = new JsonArray(); for (int o = 0; o < ps.getChild(i).getChildCount(); o++) { ja.add(traversePS(ps.getChild(i).getChild(o), child)); } siebJSON.add(ps.getChild(i).getType().substring(7), ja); } else if (ps.getChild(i).getType().startsWith("StringList-")) { JsonArray ja = new JsonArray(); SiebelPropertySet auxps = ps.getChild(i); Enumeration e = auxps.getPropertyNames(); List list = Collections.list(e); Collections.sort(list); e = Collections.enumeration(list); while (e.hasMoreElements()) { String propName1 = (String) e.nextElement(); ja.add(new JsonPrimitive(auxps.getProperty(propName1))); } siebJSON.add(auxps.getType().substring(11), ja); } else { child = traversePS(ps.getChild(i), child); siebJSON.add(ps.getChild(i).getType(), child); } } return siebJSON; }
From source file:TimedOut.java
License:Apache License
public static JsonObject main(JsonObject args) throws InterruptedException { Thread.sleep(310000);// ww w . j a va2 s . c om return new JsonObject(); }
From source file:CustomAudienceExample.java
License:Open Source License
public static void main(String[] args) { try {// w w w . ja v a 2 s . c o m AdAccount account = new AdAccount(ACCOUNT_ID, context); CustomAudience audience = account.createCustomAudience().setName("Java SDK Test Custom Audience") .setDescription("Test Audience").setSubtype(EnumSubtype.VALUE_CUSTOM).execute(); // Audience payload schema JsonArray schema = new JsonArray(); schema.add(new JsonPrimitive("EMAIL_SHA256")); schema.add(new JsonPrimitive("PHONE_SHA256")); // Audience payload data JsonArray personA = new JsonArray(); personA.add(new JsonPrimitive(sha256("aaa@example.com"))); personA.add(new JsonPrimitive(sha256("1234567890"))); JsonArray personB = new JsonArray(); personB.add(new JsonPrimitive(sha256("bbb@example.com"))); personB.add(new JsonPrimitive(sha256("1234567890"))); JsonArray personC = new JsonArray(); personC.add(new JsonPrimitive(sha256("ccc@example.com"))); personC.add(new JsonPrimitive(sha256("1234567890"))); JsonArray data = new JsonArray(); data.add(personA); data.add(personB); data.add(personC); JsonObject payload = new JsonObject(); payload.add("schema", schema); payload.add("data", data); audience.createUser().setPayload(payload.toString()).execute(); System.out.println(audience.fetch()); Targeting targeting = new Targeting().setFieldCustomAudiences("[{id:" + audience.getId() + "}]"); Campaign campaign = account.createCampaign().setName("Java SDK Test Campaign") .setObjective(Campaign.EnumObjective.VALUE_LINK_CLICKS).setSpendCap(10000L) .setStatus(Campaign.EnumStatus.VALUE_PAUSED).execute(); AdSet adset = account.createAdSet().setName("Java SDK Test AdSet").setCampaignId(campaign.getFieldId()) .setStatus(AdSet.EnumStatus.VALUE_PAUSED) .setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS).setDailyBudget(1000L) .setBidAmount(100L).setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_IMPRESSIONS) .setTargeting(targeting).setRedownload(true).requestAllFields().execute(); System.out.println(adset); AdImage image = account.createAdImage().addUploadFile("file", imageFile).execute(); AdCreative creative = account.createAdCreative().setTitle("Java SDK Test Creative") .setBody("Java SDK Test Creative").setImageHash(image.getFieldHash()) .setLinkUrl("www.facebook.com").setObjectUrl("www.facebook.com").execute(); Ad ad = account.createAd().setName("Java SDK Test ad").setAdsetId(Long.parseLong(adset.getId())) .setCreative(creative).setStatus("PAUSED").setBidAmount(100L).setRedownload(true).execute(); } catch (APIException e) { e.printStackTrace(); } }
From source file:$groupId.FunctionApp.java
License:Apache License
public static JsonObject main(JsonObject args) { JsonObject response = new JsonObject(); response.addProperty("greetings", "Hello! Welcome to OpenWhisk"); return response; }
From source file:account.BajajReport.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from ww w.jav a 2s. 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 { final String from_date = request.getParameter("from_date"); final String to_date = request.getParameter("to_date"); final String ac_cd = request.getParameter("ac_cd"); final int branch_cd = Integer.parseInt(request.getParameter("branch_cd")); final DBHelper helper = DBHelper.GetDBHelper(); final Connection dataConnection = helper.getConnMpAdmin(); final JsonObject jResultObj = new JsonObject(); final Library lb = Library.getInstance(); if (dataConnection != null) { try { String sql = "select v1.v_type,v1.branch_cd,v.ref_no,v1.inv_no,a.FNAME,s.SR_NAME,v1.V_DATE as ins_date,v.TAG_NO,p.BAJAJ_AMT,p.SFID,a1.fname as bajaj_name from vilsdt v " + " left join SERIESMST s on v.SR_CD=s.SR_CD left join VILSHD v1 on v.REF_NO=v1.REF_NO left join acntmst a on v1.AC_CD=a.AC_CD " + " left join payment p on v1.ref_no=p.ref_no left join acntmst a1 on p.bajaj_name=a1.ac_cd " + " where v1.V_DATE>='" + from_date + "'" + " and v1.V_DATE<='" + to_date + "' and v1.is_del=0 and p.bajaj_amt <>0 " + " and (v.IMEI_NO<>'' or v.SERAIL_NO<>'') and v.is_main=1"; if (branch_cd != 0) { sql += " and v1.branch_cd=" + branch_cd; } if (!ac_cd.equalsIgnoreCase("")) { sql += " and p.bajaj_name='" + ac_cd + "'"; } sql += " order by v1.V_DATE"; PreparedStatement pstLocal = dataConnection.prepareStatement(sql); ResultSet viewDataRs = pstLocal.executeQuery(); JsonArray array = new JsonArray(); while (viewDataRs.next()) { JsonObject object = new JsonObject(); object.addProperty("INV_NO", viewDataRs.getString("INV_NO")); object.addProperty("V_TYPE", viewDataRs.getString("V_TYPE")); object.addProperty("FNAME", viewDataRs.getString("FNAME")); object.addProperty("SR_NAME", viewDataRs.getString("SR_NAME")); object.addProperty("TAG_NO", viewDataRs.getString("TAG_NO")); object.addProperty("INS_DATE", viewDataRs.getString("ins_date")); object.addProperty("branch_cd", viewDataRs.getString("branch_cd")); object.addProperty("RATE", viewDataRs.getDouble("BAJAJ_AMT")); object.addProperty("REF_NO", viewDataRs.getString("REF_NO")); object.addProperty("SFID", viewDataRs.getString("SFID")); object.addProperty("BAJAJ_NAME", viewDataRs.getString("BAJAJ_NAME")); array.add(object); } lb.closeResultSet(viewDataRs); lb.closeStatement(pstLocal); 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()); } finally { lb.closeConnection(dataConnection); } } response.getWriter().print(jResultObj); }
From source file:account.BankBook.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w w w . j ava2 s . c o 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 { DBHelper helper = DBHelper.GetDBHelper(); dataConnection = helper.getConnMpAdmin(); final JsonObject jResultObj = new JsonObject(); ac_cd = request.getParameter("ac_cd"); rec_date = Boolean.parseBoolean(request.getParameter("rec_date")); from_date = request.getParameter("from_date"); to_date = request.getParameter("to_date"); try { if (dataConnection != null) { makeQuery(); double opbRs = 0.00; JsonArray array = new JsonArray(); while (viewDataRS.next()) { JsonObject object = new JsonObject(); object.addProperty("DOC_REF_NO", viewDataRS.getString("INV_NO")); object.addProperty("DOC_DATE", viewDataRS.getString("DOC_DATE")); object.addProperty("REC_DATE", viewDataRS.getString("REC_DATE")); object.addProperty("DOC_CD", viewDataRS.getString("DOC_CD")); object.addProperty("DR", viewDataRS.getDouble("DR")); object.addProperty("CR", viewDataRS.getDouble("CR")); opbRs += viewDataRS.getDouble("DR") - viewDataRS.getDouble("CR"); object.addProperty("BAL", opbRs); object.addProperty("PARTICULAR", viewDataRS.getString("PARTICULAR")); object.addProperty("OPP_AC_CD", viewDataRS.getString("OPP_AC_CD")); object.addProperty("REC_DATE", viewDataRS.getString("REC_DATE")); object.addProperty("OPP_NAME", viewDataRS.getString("OPP_NAME")); object.addProperty("REF_NO", viewDataRS.getString("doc_ref_no")); object.addProperty("CHQ_NO", viewDataRS.getString("CHQ_NO")); object.addProperty("REC_BANK_NAME", viewDataRS.getString("REC_BANK_NAME")); array.add(object); } String sql = "(select (select case when sum(val) is null then 0 else sum(val)end from OLDB2_2 where AC_CD='" + ac_cd + "' and ((doc_date <'" + from_date + "') and (REC_DATE <'" + from_date + "')) and CRDR=0) -" + "(select case when sum(val) is null then 0 else sum(val)end from OLDB2_2 where AC_CD='" + ac_cd + "' " + "and ((doc_date <'" + from_date + "') and (REC_DATE <'" + from_date + "')) and CRDR=1) as opb from dual) "; PreparedStatement pstLocal = dataConnection.prepareStatement(sql); viewDataRS = pstLocal.executeQuery(); if (viewDataRS.next()) { jResultObj.addProperty("opb", viewDataRS.getDouble("opb")); } else { jResultObj.addProperty("opb", 0.00); } 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); }