List of usage examples for com.google.gson JsonObject getAsJsonPrimitive
public JsonPrimitive getAsJsonPrimitive(String memberName)
From source file:com.ibasco.agql.protocols.valve.steam.webapi.interfaces.SteamStorefront.java
License:Open Source License
public CompletableFuture<StoreAppDetails> getAppDetails(int appId, String countryCode, String language) { CompletableFuture<JsonObject> json = sendRequest( new GetAppDetails(VERSION_1, appId, countryCode, language)); return json.thenApply(root -> { JsonObject appObject = root.getAsJsonObject(String.valueOf(appId)); if (appObject.getAsJsonPrimitive("success").getAsBoolean()) { JsonObject appData = appObject.getAsJsonObject("data"); return fromJson(appData, StoreAppDetails.class); }/* w w w . j a va 2s . c om*/ return null; }); }
From source file:com.ibasco.agql.protocols.valve.steam.webapi.interfaces.SteamUser.java
License:Open Source License
public CompletableFuture<Long> getSteamIdFromVanityUrl(String urlPath, VanityUrlType type) { CompletableFuture<JsonObject> json = sendRequest(new ResolveVanityURL(VERSION_1, urlPath, type)); return json.thenApply(root -> { JsonObject response = root.getAsJsonObject("response"); int success = response.getAsJsonPrimitive("success").getAsInt(); if (success == 1) { String steamId = response.getAsJsonPrimitive("steamid").getAsString(); if (!StringUtils.isEmpty(steamId) && StringUtils.isNumeric(steamId)) { return Long.valueOf(steamId); }/*from w w w . ja va 2 s .c o m*/ } return null; }); }
From source file:com.ibm.g11n.pipeline.client.ServiceAccount.java
License:Open Source License
/** * Returns an instance of ServiceAccount for a JsonArray in the VCAP_SERVICES environment. * <p>// www . j a v a 2 s . c o m * This method is called from {@link #getInstanceByVcapServices(String, String)}. * * @param jsonArray * The candidate JSON array which may include valid credentials. * @param serviceInstanceName * The name of IBM Globalization Pipeline service instance, or null * designating the first available service instance. * @return An instance of ServiceAccount. This method returns null if no matching service * instance name was found (when serviceInstanceName is null), or no valid * credential data was found. */ private static ServiceAccount parseToServiceAccount(JsonArray jsonArray, String serviceInstanceName) { ServiceAccount account = null; for (int i = 0; i < jsonArray.size(); i++) { JsonObject gpObj = jsonArray.get(i).getAsJsonObject(); if (serviceInstanceName != null) { // When service instance name is specified, // this method returns only a matching entry JsonPrimitive name = gpObj.getAsJsonPrimitive("name"); if (name == null || !serviceInstanceName.equals(name.getAsString())) { continue; } } JsonObject credentials = gpObj.getAsJsonObject("credentials"); if (credentials == null) { continue; } JsonPrimitive jsonUrl = credentials.getAsJsonPrimitive("url"); JsonPrimitive jsonInstanceId = credentials.getAsJsonPrimitive("instanceId"); JsonPrimitive jsonUserId = credentials.getAsJsonPrimitive("userId"); JsonPrimitive jsonPassword = credentials.getAsJsonPrimitive("password"); if (jsonUrl != null && jsonInstanceId != null && jsonUserId != null & jsonPassword != null) { account = getInstance(jsonUrl.getAsString(), jsonInstanceId.getAsString(), jsonUserId.getAsString(), jsonPassword.getAsString()); logger.config("A ServiceAccount is created from VCAP_SERVICES: url=" + jsonUrl + ", instanceId=" + jsonInstanceId + ", userId=" + jsonUserId + ", password=***"); break; } } return account; }
From source file:com.ibm.gaas.ServiceAccount.java
License:Open Source License
/** * Returns an instance of ServiceAccount from the VCAP_SERVICES environment * variable. When <code>serviceInstanceName</code> is null, this method returns * a ServiceAccount for the first valid IBM Globlization service instance. * If <code>serviceInstanceName</code> is not null, this method look up a * matching service entry, and returns a ServiceAccount for the matching entry. * If <code>serviceInstanceName</code> is not null and there is no match, * this method returns null./*from www. ja v a 2 s. c o m*/ * * @param serviceInstanceName * The name of the IBM Globalization service instance, or null * designating the first available service instance. * @return An instance of ServiceAccount for the specified service instance * name, or null. */ private static ServiceAccount getInstanceByVcapServices(String serviceInstanceName) { Map<String, String> env = System.getenv(); String vcapServices = env.get("VCAP_SERVICES"); if (vcapServices == null) { return null; } ServiceAccount account = null; try { JsonObject obj = new JsonParser().parse(vcapServices).getAsJsonObject(); JsonArray gaasArray = obj.getAsJsonArray(GAAS_SERVICE_NAME); if (gaasArray != null) { for (int i = 0; i < gaasArray.size(); i++) { JsonObject gaasEntry = gaasArray.get(i).getAsJsonObject(); if (serviceInstanceName != null) { // When service instance name is specified, // this method returns only a matching entry JsonPrimitive name = gaasEntry.getAsJsonPrimitive("name"); if (name == null || !serviceInstanceName.equals(name.getAsString())) { continue; } } JsonObject credentials = gaasEntry.getAsJsonObject("credentials"); if (credentials == null) { continue; } JsonPrimitive jsonUri = credentials.getAsJsonPrimitive("uri"); JsonPrimitive jsonApiKey = credentials.getAsJsonPrimitive("api_key"); if (jsonUri != null && jsonApiKey != null) { logger.info( "A ServiceAccount is created from VCAP_SERVICES: uri=" + jsonUri + ", api_key=***"); account = getInstance(jsonUri.getAsString(), jsonApiKey.getAsString()); break; } } } } catch (JsonParseException e) { // Fall through - will return null } return account; }
From source file:com.ibm.matos.Config.java
License:Apache License
public void overrideProperties(JsonObject props) { // override config properties with those passed in params for (String prop : Config.ALL_PROPS) { if (props.has(prop)) matos.addProperty(prop, props.getAsJsonPrimitive(prop).getAsString()); }/*from ww w . ja v a 2 s. com*/ }
From source file:com.ibm.mil.readyapps.summit.utilities.Utils.java
License:Open Source License
private static JsonElement getJsonPrimitive(String json) { JsonParser parser = new JsonParser(); JsonObject jsonObject = parser.parse(json).getAsJsonObject(); JsonPrimitive jsonPrimitive = jsonObject.getAsJsonPrimitive("result"); return parser.parse(jsonPrimitive.getAsString()); }
From source file:com.ibm.streamsx.edgevideo.device.edgent.JsonMat.java
License:Open Source License
public static Mat fromJsonObject(JsonObject joMat) { int width = joMat.getAsJsonPrimitive("width").getAsInt(); int height = joMat.getAsJsonPrimitive("height").getAsInt(); int type = joMat.getAsJsonPrimitive("type").getAsInt(); Mat face = JsonMat.base64MimeDecodeMat(width, height, type, joMat.get("mat").getAsString()); return face;//from ww w . j av a2 s. co m }
From source file:com.ibm.streamsx.topology.generator.spl.OperatorGenerator.java
License:Open Source License
private static void asFloat64(StringBuilder sb, JsonObject obj, String key) { SPLGenerator.numberLiteral(sb, obj.getAsJsonPrimitive(key), "FLOAT64"); }
From source file:com.idahokenpo.kenposchedule.data.serialization.WeekIdentifierDeserializer.java
@Override public WeekIdentifier deserialize(JsonElement json, Type type, JsonDeserializationContext jdc) throws JsonParseException { JsonObject obj = json.getAsJsonObject(); int weekOfYear = obj.getAsJsonPrimitive("weekOfYear").getAsInt(); int year = obj.getAsJsonPrimitive("year").getAsInt(); LocalDate date = LocalDate.parse(obj.getAsJsonPrimitive("billingDate").getAsString()); return new WeekIdentifier(weekOfYear, year, date); }
From source file:com.imaginea.betterdocs.BetterDocsAction.java
License:Apache License
private ArrayList<Integer> getLineNumbers(Collection<String> imports, String tokens) { ArrayList<Integer> lineNumbers = new ArrayList<Integer>(); JsonReader reader = new JsonReader(new StringReader(tokens)); reader.setLenient(true);//from w w w . j av a 2s . c o m JsonArray tokensArray = new JsonParser().parse(reader).getAsJsonArray(); for (JsonElement token : tokensArray) { JsonObject jObject = token.getAsJsonObject(); String importName = jObject.getAsJsonPrimitive(IMPORT_NAME).getAsString(); if (imports.contains(importName)) { JsonArray lineNumbersArray = jObject.getAsJsonArray(LINE_NUMBERS); for (JsonElement lineNumber : lineNumbersArray) { lineNumbers.add(lineNumber.getAsInt()); } } } return lineNumbers; }