List of usage examples for com.google.gson JsonPrimitive JsonPrimitive
public JsonPrimitive(Character c)
From source file:com.google.iosched.model.validator.SessionURLConverter.java
License:Open Source License
@Override public JsonPrimitive convert(JsonPrimitive sessionId) { if (sessionId == null) { return null; }// w w w .j a v a 2 s . c o m return new JsonPrimitive(Config.SESSION_BASE_URL + sessionId.getAsString()); }
From source file:com.google.iosched.model.validator.StringObfuscateConverter.java
License:Open Source License
@Override public JsonPrimitive convert(JsonPrimitive value) { if (value == null) { return null; }//w w w .java2s .c o m return new JsonPrimitive(obfuscate(value.getAsString())); }
From source file:com.google.iosched.model.validator.TagNameConverter.java
License:Open Source License
@Override public JsonPrimitive convert(JsonPrimitive value) { if (value == null) { return null; }// www . j a v a 2s . c om return new JsonPrimitive(value.getAsString().toUpperCase().replace('/', '_').replaceAll("[ ']", "")); }
From source file:com.google.iosched.model.validator.YoutubeURLConverter.java
License:Open Source License
@Override public JsonPrimitive convert(JsonPrimitive value) { if (value == null) { if (acceptsNull) { return null; } else {/*from w w w. j a v a 2 s .c o m*/ throw new ConverterException(value, this); } } String str = value.getAsString(); if (acceptsNull && str.isEmpty()) { return value; } for (Pattern p : patterns) { Matcher m = p.matcher(str); if (m.find()) { return new JsonPrimitive(outFormat.format(new String[] { m.group(1) })); } } throw new ConverterException(value, this); }
From source file:com.google.iosched.server.servlet.LogDataServlet.java
License:Open Source License
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setContentType("application/json"); UpdateRunLogger logger = new UpdateRunLogger(); JsonObject response = new JsonObject(); int limitElements = 10; if (req.getParameter("limit") != null) { limitElements = Integer.parseInt(req.getParameter("limit")); }//w ww . j a v a2 s. com List<Entity> lastRunsEntities = logger.getMostRecentRuns(limitElements); JsonArray lastRuns = new JsonArray(); for (Entity run : lastRunsEntities) { JsonObject obj = new JsonObject(); JsonObject timings = new JsonObject(); TreeMap<String, Object> sortedMap = new TreeMap<String, Object>(run.getProperties()); for (Entry<String, Object> property : sortedMap.entrySet()) { Object value = property.getValue(); String key = property.getKey(); if (key.startsWith("time_")) { timings.add(key.substring("time_".length()), new JsonPrimitive((Number) value)); } else { JsonPrimitive converted = null; if (value instanceof ShortBlob) { converted = new JsonPrimitive(bytesToHex(((ShortBlob) value).getBytes())); } else if (value instanceof String) { converted = new JsonPrimitive((String) value); } else if (value instanceof Number) { converted = new JsonPrimitive((Number) value); } else if (value instanceof Boolean) { converted = new JsonPrimitive((Boolean) value); } else if (value instanceof Character) { converted = new JsonPrimitive((Character) value); } else if (value instanceof Date) { converted = new JsonPrimitive(DateFormat.getDateTimeInstance().format((Date) value)); } if (converted != null) { obj.add(key, converted); } } } obj.add("timings", timings); lastRuns.add(obj); } response.add("lastruns", lastRuns); CloudFileManager cloudManager = new CloudFileManager(); response.add("bucket", new JsonPrimitive(cloudManager.getBucketName())); response.add("productionManifest", new JsonPrimitive(cloudManager.getProductionManifestURL())); response.add("stagingManifest", new JsonPrimitive(cloudManager.getStagingManifestURL())); new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create().toJson(response, resp.getWriter()); }
From source file:com.google.javascript.jscomp.JSModuleGraph.java
License:Apache License
/** * Returns a JSON representation of the JSModuleGraph. Specifically a * JsonArray of "Modules" where each module has a * - "name"/*w w w . j a va2 s .com*/ * - "dependencies" (list of module names) * - "transitive-dependencies" (list of module names, deepest first) * - "inputs" (list of file names) * @return List of module JSONObjects. */ @GwtIncompatible("com.google.gson") JsonArray toJson() { JsonArray modules = new JsonArray(); for (JSModule module : getAllModules()) { JsonObject node = new JsonObject(); try { node.add("name", new JsonPrimitive(module.getName())); JsonArray deps = new JsonArray(); node.add("dependencies", deps); for (JSModule m : module.getDependencies()) { deps.add(new JsonPrimitive(m.getName())); } JsonArray transitiveDeps = new JsonArray(); node.add("transitive-dependencies", transitiveDeps); for (JSModule m : getTransitiveDepsDeepestFirst(module)) { transitiveDeps.add(new JsonPrimitive(m.getName())); } JsonArray inputs = new JsonArray(); node.add("inputs", inputs); for (CompilerInput input : module.getInputs()) { inputs.add(new JsonPrimitive(input.getSourceFile().getOriginalPath())); } modules.add(node); } catch (JsonParseException e) { Throwables.propagate(e); } } return modules; }
From source file:com.google.paymentexpress.jwt.FullWalletRequest.java
License:Apache License
/** * Converts Object to HashMap to add in JWT payload * //from ww w. j a v a 2 s.c om * @return HashMap of JWT content */ public HashMap<String, JsonElement> getContent() { Gson gson = GsonHelper.getGson(); JsonObject obj = gson.toJsonTree(getCart()).getAsJsonObject(); HashMap<String, JsonElement> content = new HashMap<String, JsonElement>(); content.put("origin", new JsonPrimitive(getOrigin())); content.put("cart", obj); if (getTransaction_id() != null) content.put("transaction_id", new JsonPrimitive(getTransaction_id())); if (getTransaction_url() != null) content.put("transaction_url", new JsonPrimitive(getTransaction_url())); content.put("google_transaction_id", new JsonPrimitive(getGoogle_transaction_id())); return content; }
From source file:com.google.paymentexpress.jwt.MaskedWalletRequest.java
License:Apache License
/** * Converts Object to HashMap to add in JWT payload * /*w w w .ja v a 2 s .co m*/ * @return HashMap of JWT content */ public HashMap<String, JsonElement> getContent() { Gson gson = GsonHelper.getGson(); JsonObject obj = gson.toJsonTree(getSelectors()).getAsJsonObject(); HashMap<String, JsonElement> content = new HashMap<String, JsonElement>(); content.put("origin", new JsonPrimitive(getOrigin())); if (getTransaction_id() != null) content.put("transaction_id", new JsonPrimitive(getTransaction_id())); content.put("selectors", obj); if (getGoogle_transaction_id() != null) { content.put("google_transaction_id", new JsonPrimitive(getGoogle_transaction_id())); } return content; }
From source file:com.google.paymentexpress.jwt.TransactionStatusNotification.java
License:Apache License
@Override public HashMap<String, JsonElement> getContent() { HashMap<String, JsonElement> content = new HashMap<String, JsonElement>(); content.put("google_transaction_id", new JsonPrimitive(getGoogle_transaction_id())); content.put("status", new JsonPrimitive(getStatus())); if (getReason() != null) content.put("reason", new JsonPrimitive(getReason())); if (getDetailed_reason() != null) content.put("detailed_reason", new JsonPrimitive(getDetailed_reason())); return content; }
From source file:com.google.samples.apps.iosched.server.schedule.model.DataExtractor.java
License:Open Source License
public JsonArray extractRooms(JsonDataSources sources) { HashSet<String> ids = new HashSet<String>(); JsonArray result = new JsonArray(); JsonDataSource source = sources.getSource(InputJsonKeys.VendorAPISource.MainTypes.rooms.name()); if (source != null) { for (JsonObject origin : source) { JsonObject dest = new JsonObject(); JsonElement originalId = get(origin, InputJsonKeys.VendorAPISource.Rooms.id); String id = Config.ROOM_MAPPING.getRoomId(originalId.getAsString()); if (!ids.contains(id)) { String title = Config.ROOM_MAPPING.getTitle(id, get(origin, InputJsonKeys.VendorAPISource.Rooms.name).getAsString()); set(new JsonPrimitive(id), dest, OutputJsonKeys.Rooms.id); set(originalId, dest, OutputJsonKeys.Rooms.original_id); set(new JsonPrimitive(title), dest, OutputJsonKeys.Rooms.name); result.add(dest);//from ww w .ja v a2 s. c om ids.add(id); } } } if (Config.DEBUG_FIX_DATA) { DebugDataExtractorHelper.changeRooms(result); } return result; }