List of usage examples for com.google.gson FieldNamingPolicy UPPER_CAMEL_CASE
FieldNamingPolicy UPPER_CAMEL_CASE
To view the source code for com.google.gson FieldNamingPolicy UPPER_CAMEL_CASE.
Click Source Link
From source file:io.bitsquare.util.Utilities.java
License:Open Source License
public static String objectToJson(Object object) { Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).setPrettyPrinting() .create();/*ww w. j a v a 2 s .c o m*/ return gson.toJson(object); }
From source file:ke.co.tawi.babblesms.server.servlet.ajax.admin.GetSource.java
License:Open Source License
/** * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) *//*from w ww . j av a 2 s .c o m*/ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Account account = new Account(); String accountUuid = request.getParameter("accountuuid"); Element element; if ((element = accountsCache.get(accountUuid)) != null) { account = (Account) element.getObjectValue(); } OutputStream out = response.getOutputStream(); response.setContentType("application/json;charset=UTF-8"); // Instantiate the JSon // The '=' sign is encoded to \u003d. Hence you need to use // disableHtmlEscaping(). Gson gson = new GsonBuilder().disableHtmlEscaping().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE) .setPrettyPrinting().serializeNulls().create(); out.write(gson.toJson(getSource(account)).getBytes()); out.flush(); out.close(); }
From source file:ke.co.tawi.babblesms.server.servlet.ajax.client.GetBalance.java
License:Open Source License
/** * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) *///from ww w . j a v a 2s .com @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String accountUuid = request.getParameter("accountuuid"); Element element; Account account = null; if ((element = accountsCache.get(accountUuid)) != null) { account = (Account) element.getObjectValue(); } OutputStream out = response.getOutputStream(); response.setContentType("application/json;charset=UTF-8"); // Instantiate the JSon // The '=' sign is encoded to \u003d. Hence you need to use // disableHtmlEscaping(). Gson gson = new GsonBuilder().disableHtmlEscaping().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE) .setPrettyPrinting().serializeNulls().create(); out.write(gson.toJson(getSMS(account)).getBytes()); out.flush(); out.close(); }
From source file:ke.co.tawi.babblesms.server.servlet.ajax.client.GetGroups.java
License:Open Source License
/** * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse) *//* w w w . j av a2 s. c om*/ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Account account = new Account(); String accountUuid = request.getParameter("accountuuid"); Element element; if ((element = accountsCache.get(accountUuid)) != null) { account = (Account) element.getObjectValue(); } OutputStream out = response.getOutputStream(); response.setContentType("application/json;charset=UTF-8"); // Instantiate the JSon // The '=' sign is encoded to \u003d. Hence you need to use // disableHtmlEscaping(). Gson gson = new GsonBuilder().disableHtmlEscaping().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE) .setPrettyPrinting().serializeNulls().create(); out.write(gson.toJson(getGroupMaps(account)).getBytes()); out.flush(); out.close(); }
From source file:ke.co.tawi.babblesms.server.servlet.report.chart.bar.IncomingBarDay.java
License:Open Source License
/** * Creates Json information for incoming SMS information against all * {@link Network}s./*from www . ja v a 2 s . c o m*/ * <p> * An example is:<br/> * {"incomingData":[{"date":"Apr 20","orange_ke":98,"safaricom_ke":145,"airtel_ke":63}, {"date":"Apr 21","orange_ke":70,"safaricom_ke":180,"airtel_ke":120}, {"date":"Apr 22","orange_ke":20,"safaricom_ke":100,"airtel_ke":140}, {"date":"Apr 23","orange_ke":5,"safaricom_ke":20,"airtel_ke":9}, {"date":"Apr 24","orange_ke":65,"safaricom_ke":56,"airtel_ke":10}, {"date":"Apr 25","orange_ke":27,"safaricom_ke":72,"airtel_ke":75}, {"date":"Apr 26","orange_ke":102,"safaricom_ke":63,"airtel_ke":48} ]} * * @return a Json String */ private String getJsonIncoming(String accountUuid) { Gson g = new GsonBuilder().disableHtmlEscaping().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE) .setPrettyPrinting().serializeNulls().create(); HashMap<String, List<Map<String, Object>>> countHash = new HashMap<>(); SessionStatistics statistics = new SessionStatistics(); Element element; String dateStr; if ((element = statisticsCache.get(accountUuid)) != null) { statistics = (SessionStatistics) element.getObjectValue(); } Map<String, Map<Network, Integer>> networkIncomingUSSDCountDay = new HashMap<String, Map<Network, Integer>>(); DateTime dateMidnightStart; // TODO sort out calculations of dates if (fromDate == null) { dateMidnightStart = new DateTime(fromDate); } else { dateMidnightStart = DateTime.now().minus(Hours.hours(24 * (DAY_COUNT))); } int numDays = 0; if ((element = statisticsCache.get(accountUuid)) != null) { statistics = (SessionStatistics) element.getObjectValue(); } networkIncomingUSSDCountDay = statistics.getNetworkIncomingUSSDCountDay(); Map<Network, Integer> networkIncomingUSSDCount; // Hold the network and dates with SMS counts ArrayList<Map<String, Object>> dateNetworkCountArray = new ArrayList<Map<String, Object>>(); Iterator<Network> networkIter; Network network; do { dateStr = new SimpleDateFormat("MMM d").format(new Date(dateMidnightStart.getMillis())); networkIncomingUSSDCount = networkIncomingUSSDCountDay.get(dateStr); // recreate the Map in order to void duplicating data HashMap<String, Object> dateNetworkCount = new HashMap<String, Object>(); // It is possible that on particular days the account has no // incoming SMS if (networkIncomingUSSDCount != null) { networkIter = networkIncomingUSSDCount.keySet().iterator(); dateNetworkCount.put("date", dateStr.toString()); while (networkIter.hasNext()) { network = networkIter.next(); // add network names and SMS count to Map. Remove spaces in // the network name to avoid typeErrors in JavaScript dateNetworkCount.put(network.getName().replace(" ", "_").toLowerCase(), networkIncomingUSSDCount.get(network)); } // add the network statistics and the date to an array. It will // be converted to a JSON array dateNetworkCountArray.add(dateNetworkCount); } // increase the date by 24hours dateMidnightStart = dateMidnightStart.plus(Hours.hours(24)); numDays++; } while (numDays < DAY_COUNT); // finally put the array into a Map which can be converted into a JSON // object countHash.put("incomingData", dateNetworkCountArray); return g.toJson(countHash); }
From source file:ke.co.tawi.babblesms.server.servlet.report.chart.bar.OutgoingBarDay.java
License:Open Source License
/** * Creates Json information for outgoing SMS information against all * {@link Network}s.// www .j av a 2s . co m * <p> * An example is:<br/> * {"outgoingData":[{"date":"Apr 20","orange_ke":98,"safaricom_ke":145,"airtel_ke":63}, * {"date":"Apr 21","orange_ke":70,"safaricom_ke":180,"airtel_ke":120}, {"date":"Apr 22","orange_ke":20,"safaricom_ke":100,"airtel_ke":140}, {"date":"Apr 23","orange_ke":5,"safaricom_ke":20,"airtel_ke":9}, {"date":"Apr 24","orange_ke":65,"safaricom_ke":56,"airtel_ke":10}, {"date":"Apr 25","orange_ke":27,"safaricom_ke":72,"airtel_ke":75}, {"date":"Apr 26","orange_ke":102,"safaricom_ke":63,"airtel_ke":48} ]} * * @return a Json String */ private String getJsonOutgoing(String accountUuid) { Gson g = new GsonBuilder().disableHtmlEscaping().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE) .setPrettyPrinting().serializeNulls().create(); HashMap<String, ArrayList<Map<String, Object>>> countHash = new HashMap<>(); SessionStatistics statistics = new SessionStatistics(); Element element; String dateStr; if ((element = statisticsCache.get(accountUuid)) != null) { statistics = (SessionStatistics) element.getObjectValue(); } Map<String, Map<Network, Integer>> networkOutgoingUSSDCountDay = new HashMap<String, Map<Network, Integer>>(); // TODO sort out calculations of dates DateTime dateMidnightStart; if (fromDate == null) { dateMidnightStart = new DateTime(fromDate); } else { dateMidnightStart = DateTime.now().minus(Hours.hours(24 * (DAY_COUNT))); } int numDays = 0; if ((element = statisticsCache.get(accountUuid)) != null) { statistics = (SessionStatistics) element.getObjectValue(); } networkOutgoingUSSDCountDay = statistics.getNetworkOutgoingUSSDCountDay(); Map<Network, Integer> networkOutgoingUSSDCount; // Hold the network and dates with SMS counts ArrayList<Map<String, Object>> dateNetworkCountArray = new ArrayList<Map<String, Object>>(); Iterator<Network> networkIter; Network network; do { dateStr = new SimpleDateFormat("MMM d").format(new Date(dateMidnightStart.getMillis())); networkOutgoingUSSDCount = networkOutgoingUSSDCountDay.get(dateStr); // recreate the Map in order to void duplicating data HashMap<String, Object> dateNetworkCount = new HashMap<String, Object>(); // It is possible that on particular days the account has no // incoming SMS if (networkOutgoingUSSDCount != null) { networkIter = networkOutgoingUSSDCount.keySet().iterator(); dateNetworkCount.put("date", dateStr.toString()); while (networkIter.hasNext()) { network = networkIter.next(); // add network names and SMS count to Map. Remove spaces in // the network name to avoid typeErrors in JavaScript dateNetworkCount.put(network.getName().replace(" ", "_").toLowerCase(), networkOutgoingUSSDCount.get(network)); } // add the network statistics and the date to an array. It will // be converted to a JSON array dateNetworkCountArray.add(dateNetworkCount); } dateMidnightStart = dateMidnightStart.plus(Hours.hours(24)); numDays++; } while (numDays < DAY_COUNT); // finally put the array into a Map which can be converted into a JSON // object countHash.put("outgoingData", dateNetworkCountArray); return g.toJson(countHash); }
From source file:org.opendaylight.tsdr.persistence.elasticsearch.ElasticsearchStore.java
License:Open Source License
/** * Built a client configuration also base on properties file. *///from ww w .ja v a 2 s.c o m private HttpClientConfig buildClientConfig() throws IOException { GsonBuilder gson = new GsonBuilder().setFieldNamingStrategy(field -> { String name = FieldNamingPolicy.UPPER_CAMEL_CASE.translateName(field); if (name.startsWith("_")) { return name.substring(1); } return name; }).setExclusionStrategies(new ExclusionStrategy() { @Override public boolean shouldSkipField(FieldAttributes fieldAttributes) { String name = fieldAttributes.getName().toLowerCase(); return name.equals("hash") || name.equals("hashvalid"); } @Override public boolean shouldSkipClass(Class<?> clazz) { return false; } }); String serverUrl = properties.get("serverUrl"); HttpClientConfig.Builder configBuilder = new HttpClientConfig.Builder(serverUrl).multiThreaded(true) .gson(gson.create()); if (Boolean.valueOf(properties.get("nodeDiscovery"))) { configBuilder.discoveryEnabled(true).discoveryFrequency(1L, TimeUnit.MINUTES); } String username = properties.get("username"); String password = properties.get("password"); if (!Strings.isNullOrEmpty(username) && !Strings.isNullOrEmpty(password)) { configBuilder.defaultCredentials(username, password); } return configBuilder.build(); }
From source file:org.opendedup.sdfs.io.events.MFileDeleted.java
License:Open Source License
public String toJSON() { JsonObject dataset = this.toJSONObject(); dataset.addProperty("actionType", "mfileDelete"); dataset.addProperty("object", mf.getPath().substring(pl)); if (mf.isSymlink()) dataset.addProperty("fileType", "symlink"); else if (this.dir) dataset.addProperty("fileType", "dir"); else//from w w w.ja v a 2 s.c om dataset.addProperty("fileType", "file"); Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls() .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).create(); return gson.toJson(dataset); }
From source file:org.opendedup.sdfs.io.events.MFileRenamed.java
License:Open Source License
public String toJSON() { JsonObject dataset = this.toJSONObject(); dataset.addProperty("actionType", "mfileRename"); dataset.addProperty("object", mf.getPath().substring(pl)); dataset.addProperty("from", this.from); dataset.addProperty("to", this.to); if (mf.isSymlink()) dataset.addProperty("fileType", "symlink"); else if (mf.isDirectory()) dataset.addProperty("fileType", "dir"); else/*from w ww . jav a 2s . com*/ dataset.addProperty("fileType", "file"); Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls() .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).create(); return gson.toJson(dataset); }
From source file:org.opendedup.sdfs.io.events.MFileWritten.java
License:Open Source License
public String toJSON() { JsonObject dataset = this.toJSONObject(); dataset.addProperty("actionType", "mfileWritten"); dataset.addProperty("object", mf.getPath().substring(pl)); if (mf.isSymlink()) dataset.addProperty("fileType", "symlink"); else if (mf.isDirectory()) dataset.addProperty("fileType", "dir"); else {/*from w w w. j a va 2 s.c om*/ dataset.addProperty("fileType", "file"); dataset.addProperty("size", mf.length()); } Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls() .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).create(); return gson.toJson(dataset); }