List of usage examples for com.google.gson JsonObject JsonObject
JsonObject
From source file:br.unicamp.cst.bindings.soar.SOARPlugin.java
License:Open Source License
public JsonObject createJsonFromString(String pathToLeaf, double value) { String[] treeNodes = pathToLeaf.split("\\."); JsonObject json = new JsonObject(); for (int i = treeNodes.length - 1; i >= 0; i--) { JsonObject temp = new JsonObject(); if (i == treeNodes.length - 1) { temp.addProperty(treeNodes[i], value); } else {/* ww w . j a v a 2 s. co m*/ temp.add(treeNodes[i], json); } json = temp; } return json; }
From source file:br.unicamp.cst.bindings.soar.SOARPlugin.java
License:Open Source License
public JsonObject createJsonFromString(String pathToLeaf, String value) { String[] treeNodes = pathToLeaf.split("\\."); JsonObject json = new JsonObject(); for (int i = treeNodes.length - 1; i >= 0; i--) { JsonObject temp = new JsonObject(); if (i == treeNodes.length - 1) { temp.addProperty(treeNodes[i], value); } else {/* ww w . j av a2 s . c om*/ temp.add(treeNodes[i], json); } json = temp; } return json; }
From source file:br.unicamp.cst.bindings.soar.SOARPlugin.java
License:Open Source License
public JsonObject createJsonFromString(String pathToLeaf, JsonObject value) { String[] treeNodes = pathToLeaf.split("\\."); JsonObject json = new JsonObject(); for (int i = treeNodes.length - 1; i >= 0; i--) { JsonObject temp = new JsonObject(); if (i == treeNodes.length - 1) { temp.add(treeNodes[i], value); } else {/*from ww w . j a va 2 s .co m*/ temp.add(treeNodes[i], json); } json = temp; } return json; }
From source file:br.unicamp.cst.bindings.soar.SOARPlugin.java
License:Open Source License
public JsonObject fromBeanToJson(Object bean) { JsonObject json = new JsonObject(); Class type = bean.getClass(); json.add(type.getName(), new JsonObject()); try {//from w w w . j a va 2s . com Object obj = type.newInstance(); type.cast(obj); for (Field field : type.getFields()) { json.addProperty(field.getName(), field.get(bean).toString()); } } catch (Exception e) { } return json; }
From source file:brand.AddUpdateBrandMaster.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* ww w . j ava 2 s. c om*/ * * @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 DBHelper helper = DBHelper.GetDBHelper(); final Connection dataConnection = helper.getConnMpAdmin(); final Library lb = Library.getInstance(); String brand_cd = request.getParameter("brand_cd"); final String brand_name = request.getParameter("brand_name"); final String user_id = request.getParameter("user_id"); final JsonObject jResultObj = new JsonObject(); if (dataConnection != null) { try { if (brand_cd.equalsIgnoreCase("")) { brand_cd = lb.generateKey(dataConnection, "BRANDMST", "brand_cd", "B", 7); String sql = "insert into BRANDMST (brand_cd,brand_name,user_id) values(?,?,?)"; PreparedStatement pstLocal = dataConnection.prepareStatement(sql); pstLocal.setString(1, brand_cd); pstLocal.setString(2, brand_name); pstLocal.setString(3, user_id); pstLocal.executeUpdate(); } else if (!brand_cd.equalsIgnoreCase("")) { String sql = "update BRANDMST set brand_name=?,edit_no=edit_no+1,user_id=?,time_stamp=current_timestamp where brand_cd=?"; PreparedStatement pstLocal = dataConnection.prepareStatement(sql); pstLocal.setString(1, brand_name); pstLocal.setString(2, user_id); pstLocal.setString(3, brand_cd); pstLocal.executeUpdate(); } jResultObj.addProperty("result", 1); jResultObj.addProperty("Cause", "success"); jResultObj.addProperty("brand_cd", brand_cd); } 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:brand.GetBrandMaster.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w ww.ja va2s . 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 { final DBHelper helper = DBHelper.GetDBHelper(); final Connection dataConnection = helper.getConnMpAdmin(); final JsonObject jResultObj = new JsonObject(); if (dataConnection != null) { try { String sql = "select BRAND_CD,BRAND_NAME,USER_ID from BRANDMST"; PreparedStatement pstLocal = dataConnection.prepareStatement(sql); ResultSet rsLocal = pstLocal.executeQuery(); JsonArray array = new JsonArray(); while (rsLocal.next()) { JsonObject object = new JsonObject(); object.addProperty("BRAND_CD", rsLocal.getString("BRAND_CD")); object.addProperty("BRAND_NAME", rsLocal.getString("BRAND_NAME")); object.addProperty("USER_ID", rsLocal.getInt("USER_ID")); 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); }
From source file:buri.ddmsence.AbstractAccessEntity.java
License:Open Source License
/** * @see AbstractBaseComponent#getJSONObject() *///from ww w .j av a2 s . co m public JsonObject getJSONObject() { JsonObject object = new JsonObject(); if (getSystemName() != null) addJson(object, "systemName", getSystemName().getJSONObject()); addJson(object, getOutputName() + "Value", getOutputValues()); addJson(object, getSecurityAttributes()); return (object); }
From source file:buri.ddmsence.AbstractProducerRole.java
License:Open Source License
/** * @see AbstractBaseComponent#getJSONObject() *///w w w . j a va2s. c o m public JsonObject getJSONObject() { JsonObject object = new JsonObject(); addJson(object, (AbstractBaseComponent) getEntity()); addJson(object, POC_TYPE_NAME, getPocTypes()); addJson(object, getSecurityAttributes()); return (object); }
From source file:buri.ddmsence.AbstractRoleEntity.java
License:Open Source License
/** * @see AbstractBaseComponent#getJSONObject() *//*from www .j a v a 2s . c o m*/ public JsonObject getJSONObject() { JsonObject object = new JsonObject(); addJson(object, "entityType", Util.decapitalize(getName())); addJson(object, NAME_NAME, getNames()); addJson(object, PHONE_NAME, getPhones()); addJson(object, EMAIL_NAME, getEmails()); addJson(object, getExtensibleAttributes()); return (object); }
From source file:buri.ddmsence.AbstractTaskingRole.java
License:Open Source License
/** * @see AbstractBaseComponent#getJSONObject() */// w w w . j a va 2s . c om public JsonObject getJSONObject() { JsonObject object = new JsonObject(); addJson(object, (AbstractBaseComponent) getEntity()); addJson(object, getSecurityAttributes()); return (object); }