List of usage examples for com.google.gson JsonElement getAsString
public String getAsString()
From source file:com.github.autermann.matlab.json.MatlabValueSerializer.java
License:Open Source License
private MatlabDateTime parseMatlabDateTime(JsonElement value) { DateTime dt = ISODateTimeFormat.dateTime().parseDateTime(value.getAsString()); return new MatlabDateTime(dt); }
From source file:com.github.dpsm.android.print.gson.model.GsonPrinter.java
License:Apache License
@Override public String getId() { final JsonElement value = mJsonObject.get(ID); return value != null ? value.getAsString() : null; }
From source file:com.github.dpsm.android.print.gson.model.GsonPrinter.java
License:Apache License
@Override public String getName() { final JsonElement value = mJsonObject.get(NAME); return value != null ? value.getAsString() : null; }
From source file:com.github.dpsm.android.print.gson.model.GsonPrinter.java
License:Apache License
@Override public String getDescription() { final JsonElement value = mJsonObject.get(DESCRIPTION); return value != null ? value.getAsString() : null; }
From source file:com.github.frapontillo.pulse.crowd.social.extraction.ExtractionParameters.java
License:Apache License
@Override public ExtractionParameters buildFromJsonElement(JsonElement json) { ExtractionParameters extractionParameters = PluginConfigHelper.buildFromJson(json, ExtractionParameters.class); // convert the location, if any GeoLocationBoxConverter geoConverter = new GeoLocationBoxConverter(); JsonElement location = json.getAsJsonObject().get("location"); if (location != null) { extractionParameters.setGeoLocationBox(geoConverter.convert(location.getAsString())); }/*from ww w. j a v a2s. c o m*/ // normalize the query parameters List<String> query = extractionParameters.getQuery(); if (query != null) { for (int i = 0; i < query.size(); i++) { String s = query.get(i); // if the string has spaces and isn't surrounded by quotes if (s.contains(" ") && REGEX_NO_QUOTE.matcher(s).matches()) { s = "\"" + s + "\""; query.set(i, s); } } } return extractionParameters; }
From source file:com.github.frapontillo.pulse.crowd.tag.opencalais.rest.OpenCalaisResponseAdapter.java
License:Apache License
@Override public OpenCalaisResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { OpenCalaisResponse response = new OpenCalaisResponse(); for (Map.Entry<String, JsonElement> child : json.getAsJsonObject().entrySet()) { JsonObject jsonObject = child.getValue().getAsJsonObject(); JsonElement type = jsonObject.get("_typeGroup"); if (type != null && type.getAsString().equals("entities")) { response.getEntities().add(jsonObject.get("name").getAsString()); }/* w w w .j av a 2 s. c o m*/ } return response; }
From source file:com.github.ithildir.airbot.server.api.ai.AirQualityApiAiFulfillmentBuilder.java
License:Open Source License
private String _getLocationString(AIResponse aiResponse) { Result result = aiResponse.getResult(); Map<String, JsonElement> parameters = result.getParameters(); JsonElement jsonElement = parameters.get("location"); if ((jsonElement == null) || !jsonElement.isJsonObject()) { return null; }//from w ww. j a va 2 s . co m JsonObject jsonObject = jsonElement.getAsJsonObject(); jsonElement = jsonObject.get("business-name"); if (jsonElement == null) { jsonElement = jsonObject.get("city"); } return jsonElement.getAsString(); }
From source file:com.github.kyriosdata.regras.infraestrutura.ValorDeserializer.java
License:Creative Commons License
@Override public Valor deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { JsonObject jsonObject = jsonElement.getAsJsonObject(); byte tipo = jsonObject.get("tipo").getAsByte(); JsonElement valor = jsonObject.get("valor"); if (tipo == Valor.STRING) { return new Valor(valor.getAsString()); } else if (tipo == Valor.REAL) { return new Valor(valor.getAsFloat()); } else if (tipo == Valor.LOGICO) { return new Valor(valor.getAsBoolean()); } else if (tipo == Valor.DATA) { return Valor.dataFromString(valor.getAsString()); }// www .j a va2s . c o m return null; }
From source file:com.github.maoo.indexer.client.WebScriptsAlfrescoClient.java
License:Apache License
private String getString(JsonObject responseObject, String key) { if (responseObject.has(key)) { JsonElement element = responseObject.get(key); if (element.isJsonPrimitive() && element.getAsJsonPrimitive().isString()) { return element.getAsString(); } else {/*from w ww. ja va 2 s .c o m*/ logger.warn("The {} property (={}) is not a string in document: {}", new Object[] { key, element, responseObject }); } } else { logger.warn("The key {} is missing from document: {}", key, responseObject); } return ""; }
From source file:com.github.maoo.indexer.client.WebScriptsAlfrescoClient.java
License:Apache License
private String getUsername(JsonObject userObject) { if (!userObject.has(USERNAME)) { throw new AlfrescoParseException("Json response is missing username."); }/* ww w . ja va 2s.c o m*/ JsonElement usernameElement = userObject.get(USERNAME); if (!usernameElement.isJsonPrimitive() || !usernameElement.getAsJsonPrimitive().isString()) { throw new AlfrescoParseException("Username must be a string. It was: " + usernameElement.toString()); } return usernameElement.getAsString(); }