List of usage examples for com.google.gson JsonPrimitive getAsString
@Override
public String getAsString()
From source file:com.razza.apps.iosched.server.schedule.model.DataExtractor.java
License:Open Source License
private JsonPrimitive setVideoForVideoSession(JsonObject origin, JsonObject dest) { JsonPrimitive vid = getVideoFromTopicInfo(origin, InputJsonKeys.VendorAPISource.Topics.INFO_VIDEO_URL, null);// ww w . ja v a2s .c o m if (vid != null) { DataModelHelper.set(vid, dest, OutputJsonKeys.VideoLibrary.vid); JsonPrimitive thumbnail = new JsonPrimitive( "http://img.youtube.com/vi/" + vid.getAsString() + "/hqdefault.jpg"); DataModelHelper.set(thumbnail, dest, OutputJsonKeys.VideoLibrary.thumbnailUrl); } return vid; }
From source file:com.reclabs.recomendar.esdriver.helper.serializers.RecMoneyDeserializer.java
License:Open Source License
@Override public RecMoney deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObject = (JsonObject) json; JsonPrimitive currency = jsonObject.getAsJsonPrimitive("currency"); JsonPrimitive amount = jsonObject.getAsJsonPrimitive("amount"); return RecMoney.parse(currency.getAsString() + " " + amount.getAsString()); }
From source file:com.ryanantkowiak.jOptionsHouseAPI.JsonUtilities.java
License:Open Source License
/** * Recursively print the contents of a GSON JSON element. * /*from w ww . ja v a 2 s . c om*/ * @param element the GSON JSON element to be printed * @param prefix output will be prefixed with this string */ public static void printJson(JsonElement element, String prefix) { if (null == prefix || prefix.isEmpty()) { prefix = ""; } if (null == element || element.isJsonNull()) { System.out.println(prefix + " [null]"); return; } else if (element.isJsonPrimitive()) { JsonPrimitive p = element.getAsJsonPrimitive(); if (p.isBoolean()) { System.out.println(prefix + " [bool=" + p.getAsBoolean() + "]"); } else if (p.isString()) { System.out.println(prefix + " [string='" + p.getAsString() + "']"); } else if (p.isNumber()) { System.out.println(prefix + " [number=" + p.getAsDouble() + "]"); } } else if (element.isJsonArray()) { System.out.println(prefix + " [array]"); for (int i = 0; i < element.getAsJsonArray().size(); ++i) { String newPrefix = prefix + "[" + i + "]"; printJson(element.getAsJsonArray().get(i), newPrefix); } } else if (element.isJsonObject()) { JsonObject obj = element.getAsJsonObject(); for (Map.Entry<String, JsonElement> entry : obj.entrySet()) { String key = entry.getKey(); JsonElement value = entry.getValue(); String newPrefix = prefix + "." + key; printJson(value, newPrefix); } } }
From source file:com.SatanicSpider.Serialization.BodySerializer.java
public Body deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { final JsonObject jsonObject = json.getAsJsonObject(); try {//w ww . ja v a 2 s . c o m JsonPrimitive jsonP = jsonObject.getAsJsonPrimitive("json"); String jsonS = jsonP.getAsString(); //Thsi is going to fuck up on other threads ... Body b = PhysicsManager.JSONifier.j2b2Body(PhysicsManager.PhysWorld, new JSONObject(jsonS)); } catch (Exception ex) { System.err.println("Unknown Exception"); ex.printStackTrace(); } return null; }
From source file:com.SatanicSpider.Serialization.EntitySerializer.java
public Entity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { final JsonObject jsonObject = json.getAsJsonObject(); try {/*from w w w. jav a 2 s. com*/ JsonPrimitive jsonP = jsonObject.getAsJsonPrimitive("json"); String jsonS = jsonP.getAsString(); //Thsi is going to fuck up on other threads ... //Entity b = PhysicsManager.JSONifier.j2b2Body(PhysicsManager.PhysWorld, new JSONObject(jsonS)); } catch (Exception ex) { System.err.println("Unknown Exception"); ex.printStackTrace(); } return null; }
From source file:com.seleritycorp.common.base.config.ConfigUtils.java
License:Apache License
/** * Adds a JSON primitive to a Config./* ww w .jav a 2s. c o m*/ * * @param primitive The primitive to add * @param config The config instance to add the primitive to * @param key The key in the config space */ private static void loadJson(JsonPrimitive primitive, ConfigImpl config, String key) { String value = null; if (primitive.isBoolean()) { boolean bool = primitive.getAsBoolean(); value = bool ? "true" : "false"; } else if (primitive.isString()) { value = primitive.getAsString(); } else if (primitive.isNumber()) { value = Double.toString(primitive.getAsDouble()); } config.set(key, value); }
From source file:com.smartling.cms.gateway.client.internal.CommandTypeAdapter.java
License:Apache License
@Override public BaseCommand deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObject = json.getAsJsonObject(); JsonPrimitive prim = jsonObject.getAsJsonPrimitive("cmd"); String commandName = prim.getAsString(); if (commandName.equalsIgnoreCase("getResource")) { String requestId = jsonObject.getAsJsonPrimitive("rid").getAsString(); String fileUri = jsonObject.getAsJsonPrimitive("uri").getAsString(); return new GetResourceCommand(requestId, fileUri); }//from w w w. j av a2 s . c om if (commandName.equalsIgnoreCase("getHtml")) { String requestId = jsonObject.getAsJsonPrimitive("rid").getAsString(); String fileUri = jsonObject.getAsJsonPrimitive("uri").getAsString(); return new GetHtmlCommand(requestId, fileUri); } if (commandName.equalsIgnoreCase("authenticationSuccess")) { return new AuthenticationSuccessCommand(); } if (commandName.equalsIgnoreCase("authenticationError")) { return new AuthenticationErrorCommand(); } if (commandName.equalsIgnoreCase("disconnect")) { JsonPrimitive reason = jsonObject.getAsJsonPrimitive("message"); String message = reason == null ? null : reason.getAsString(); return new DisconnectCommand(message); } throw new JsonParseException("Unknown command " + commandName); }
From source file:com.softwaremagico.tm.json.AvailableSkillAdapter.java
License:Open Source License
protected String getSpecialization(JsonElement jsonElement) { JsonObject jsonObject = jsonElement.getAsJsonObject(); JsonPrimitive specialization = (JsonPrimitive) jsonObject.get(SPECIALIZATION); if (specialization == null) { return null; }//w w w . j a v a 2 s .c o m return specialization.getAsString(); }
From source file:com.softwaremagico.tm.json.ElementAdapter.java
License:Open Source License
protected String getElementId(JsonElement jsonElement) { JsonObject jsonObject = jsonElement.getAsJsonObject(); JsonPrimitive elementId = (JsonPrimitive) jsonObject.get(ID); if (elementId == null) { return null; }// www. ja va 2 s. com return elementId.getAsString(); }
From source file:com.softwaremagico.tm.json.ElementAdapter.java
License:Open Source License
protected String getLanguage(JsonElement jsonElement) { JsonObject jsonObject = jsonElement.getAsJsonObject(); JsonPrimitive language = (JsonPrimitive) jsonObject.get(LANGUAGE); if (language == null) { return null; }/* w w w . j av a2 s . c o m*/ return language.getAsString(); }