List of usage examples for com.google.gson JsonPrimitive JsonPrimitive
public JsonPrimitive(Character c)
From source file:com.asakusafw.lang.inspection.json.PortReferenceAdapter.java
License:Apache License
@Override public JsonElement serialize(InspectionNode.PortReference src, Type typeOfSrc, JsonSerializationContext context) { JsonArray result = new JsonArray(); result.add(new JsonPrimitive(src.getNodeId())); result.add(new JsonPrimitive(src.getPortId())); return result; }
From source file:com.asakusafw.yaess.tools.Explain.java
License:Apache License
private static JsonObject analyzeJobflow(FlowScript flowScript) { assert flowScript != null; JsonArray phases = new JsonArray(); for (Map.Entry<ExecutionPhase, Set<ExecutionScript>> entry : flowScript.getScripts().entrySet()) { ExecutionPhase phase = entry.getKey(); if (entry.getValue().isEmpty() == false || phase == ExecutionPhase.SETUP || phase == ExecutionPhase.CLEANUP) { phases.add(new JsonPrimitive(phase.getSymbol())); }//from w w w . jav a 2s. c o m } JsonObject jobflow = new JsonObject(); jobflow.addProperty("id", flowScript.getId()); jobflow.add("blockers", toJsonArray(flowScript.getBlockerIds())); jobflow.add("phases", phases); return jobflow; }
From source file:com.asakusafw.yaess.tools.Explain.java
License:Apache License
private static JsonArray toJsonArray(Collection<String> values) { assert values != null; JsonArray array = new JsonArray(); for (String value : values) { array.add(new JsonPrimitive(value)); }/*from www.j a va2 s . com*/ return array; }
From source file:com.atlauncher.data.mojang.PropertyMapSerializer.java
License:Open Source License
@Override public JsonElement serialize(PropertyMap src, Type typeOfSrc, JsonSerializationContext context) { JsonObject out = new JsonObject(); for (String key : src.keySet()) { JsonArray jsa = new JsonArray(); for (com.mojang.authlib.properties.Property p : src.get(key)) { jsa.add(new JsonPrimitive(p.getValue())); }/*w ww .java 2 s . co m*/ out.add(key, jsa); } return out; }
From source file:com.autoclavestudios.jbower.config.internal.JsonRegistryTranslator.java
License:Apache License
@Override public JsonElement serialize(Registry src, Type typeOfSrc, JsonSerializationContext context) { JsonElement jsonElement = null;//from w w w . java2s . c o m if (src.isSimple()) { if (src.search().size() == 1) { jsonElement = new JsonPrimitive(src.search().get(0).toString()); } } else { JsonObject jsonObject = new JsonObject(); jsonObject.add("register", ConvertToJsonArray(src.register())); jsonObject.add("search", ConvertToJsonArray(src.search())); jsonObject.add("publish", ConvertToJsonArray(src.publish())); jsonElement = jsonObject; } return jsonElement; }
From source file:com.autoclavestudios.jbower.config.internal.JsonRegistryTranslator.java
License:Apache License
private JsonArray ConvertToJsonArray(List<URL> UrlList) { JsonArray jsonArray = new JsonArray(); for (URL url : UrlList) { jsonArray.add(new JsonPrimitive(url.toString())); }/*from w ww . j a v a 2 s .c om*/ return jsonArray; }
From source file:com.awadm.CountBuilderServlet.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String action = request.getParameter("action"); //action comes with URL String uuid = request.getParameter("uuid"); //read param from url for hashtags if (uuid != null) { if (action.equals("count")) { //query String selectSQL = "SELECT TIMESTAMP, Count(ID) AS tblTimeCount FROM TBL_COUNT WHERE UUID = ? GROUP BY TIMESTAMP"; //String selectSQL = "SELECT CONVERT(VARCHAR(16), TIMESTAMP) AS timekey, Count(ID) AS tblTimeCount FROM TBL_COUNT WHERE UUID = ? GROUP BY CONVERT(VARCHAR(16), TIMESTAMP)"; try { PreparedStatement updateemp = con.prepareStatement(selectSQL); updateemp.setString(1, uuid); ResultSet rSet = updateemp.executeQuery(); Gson gson = new Gson(); JsonObject jsonResponse = new JsonObject(); JsonArray data = new JsonArray(); while (rSet.next()) { JsonArray row = new JsonArray(); row.add(new JsonPrimitive(rSet.getString("TIMESTAMP"))); row.add(new JsonPrimitive(rSet.getString("TBLTIMECOUNT"))); data.add(row);//from w w w .ja v a 2 s. c o m } jsonResponse.add("rows", data); response.getWriter().write(gson.toJson(jsonResponse)); } catch (SQLException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } } else { //no uuid came with request response.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED); } }
From source file:com.azure.webapi.DateSerializer.java
License:Open Source License
/** * Serializes a Date to a JsonElement containing a ISO-8601 formatted date *///from w ww.ja va2 s . co m @Override public JsonElement serialize(Date date, Type type, JsonSerializationContext ctx) { JsonElement element = new JsonPrimitive(serialize(date)); return element; }
From source file:com.azure.webapi.LongSerializer.java
License:Open Source License
/** * Serializes a Long instance to a JsonElement, verifying the maximum and * minimum allowed values/* w w w .j a v a2s.c o m*/ */ @Override public JsonElement serialize(Long element, Type type, JsonSerializationContext ctx) { Long maxAllowedValue = 0x0020000000000000L; Long minAllowedValue = Long.valueOf(0xFFE0000000000000L); if (element != null) { if (element > maxAllowedValue || element < minAllowedValue) { throw new InvalidParameterException( "Long value must be between " + minAllowedValue + " and " + maxAllowedValue); } else { return new JsonPrimitive(element); } } else { return JsonNull.INSTANCE; } }
From source file:com.balajeetm.mystique.core.ConcatMystTurn.java
License:Open Source License
@Override public JsonElement transmute(List<JsonElement> source, JsonObject deps, JsonObject aces, JsonObject turn) { StringBuilder stringBuilder = new StringBuilder(); if (CollectionUtils.isNotEmpty(source)) { String separator = mystiqueLever.asString(turn.get(MystiqueConstants.SEPARATOR), MystiqueConstants.EMPTY); for (int count = 0; count < source.size(); count++) { JsonElement granularSource = getGranularSource(source.get(count), turn, deps, aces); if (count != 0) { stringBuilder.append(separator); }//from w w w. ja va2 s . co m stringBuilder.append(StringUtils.strip(granularSource.toString(), MystiqueConstants.DOUBLE_QUOTES)); } } return new JsonPrimitive(stringBuilder.toString()); }