List of usage examples for com.google.gson JsonObject getAsJsonArray
public JsonArray getAsJsonArray(String memberName)
From source file:com.agwego.fuzz.FuzzTestCase.java
License:Open Source License
@SuppressWarnings("unchecked method invocation: <T>fromJson(com.google.gson.JsonElement,java.lang.Class<T>) in com.google.gson.Gson is applied to (com.google.gson.Jon: <T>fromJson(com.google.gson.JsonElement,java.lang.Class<T>) in com.google.gson.Gson is applied to (com.google.gson.J") protected static FuzzTestCase deserialize(final JsonObject jobj, final int testNumber, final String methodName, final Class testClass) throws FuzzTestJsonError { FuzzTestCase fuzzTestCase = new FuzzTestCase(); fuzzTestCase.setMethodName(methodName); fuzzTestCase.setNumber(testNumber);//from ww w .ja v a 2 s. com fuzzTestCase.setMessage(GsonHelper.getAsString(jobj, "comment")); fuzzTestCase.setExceptionThrown(GsonHelper.getAsString(jobj, "exceptionThrown")); fuzzTestCase.setExceptionMessage(GsonHelper.getAsString(jobj, "exceptionMessage")); fuzzTestCase.setSkip(GsonHelper.getAsBoolean(jobj, "skip", false)); fuzzTestCase.setPass(GsonHelper.getAsBoolean(jobj, "pass", true)); fuzzTestCase.setTestName(GsonHelper.getAsString(jobj, "name", "")); JsonArray jargs; try { jargs = jobj.getAsJsonArray("args"); } catch (ClassCastException ex) { throw new FuzzTestJsonError(String.format("Method '%s' argument list must be an array", methodName), ex); } if (jargs == null || jargs.size() == 0) { throw new FuzzTestJsonError(String.format("Method '%s' has no argument list", methodName)); } Class params[]; try { params = getMethodParams(testClass, methodName, jargs.size()); } catch (FuzzTestJsonError ex) { throw new FuzzTestJsonError(ex.getMessage()); } int idx = 0; for (JsonElement jarg : jargs) { fuzzTestCase.addArg(createArg(jarg, params[idx])); idx++; } return fuzzTestCase; }
From source file:com.android.cloudfiles.cloudfilesforandroid.CloudFiles.java
License:Apache License
private void authentication(String userName, String apiKey) throws IOException { String json = generateToken(userName, apiKey); JsonParser jsonParser = new JsonParser(); JsonObject jo = (JsonObject) jsonParser.parse(json); setToken(jo.getAsJsonObject("access").getAsJsonObject("generateToken").get("id").getAsString()); JsonArray services = jo.getAsJsonObject("access").get("serviceCatalog").getAsJsonArray(); for (JsonElement jsonElement : services) { JsonObject jobj = jsonElement.getAsJsonObject(); if (jobj.get("name").getAsString().equals("cloudFiles")) { JsonArray endpoints = jobj.getAsJsonArray("endpoints"); for (JsonElement jsonElement2 : endpoints) { urls.put(jsonElement2.getAsJsonObject().get("region").getAsString(), jsonElement2.getAsJsonObject().get("publicURL").getAsString()); }/*from www . j a v a2 s .c o m*/ } if (jobj.get("name").getAsString().equals("cloudFilesCDN")) { JsonArray endpoints = jobj.getAsJsonArray("endpoints"); for (JsonElement jsonElement2 : endpoints) { cdnUrls.put(jsonElement2.getAsJsonObject().get("region").getAsString(), jsonElement2.getAsJsonObject().get("publicURL").getAsString()); } } } }
From source file:com.android.tools.idea.gradle.structure.model.repositories.search.JCenterRepository.java
License:Apache License
SearchResult parse(@NotNull Reader response) { /*//w w w. ja va2 s. co m Sample response: [ { "name": "com.atlassian.guava:guava", "repo": "jcenter", "owner": "bintray", "desc": null, "system_ids": [ "com.atlassian.guava:guava" ], "versions": [ "15.0" ], "latest_version": "15.0" }, { "name": "com.atlassian.bundles:guava", "repo": "jcenter", "owner": "bintray", "desc": null, "system_ids": [ "com.atlassian.bundles:guava" ], "versions": [ "8.1", "8.0", "1.0-actually-8.1" ], "latest_version": "8.1" }, { "name": "io.janusproject.guava:guava", "repo": "jcenter", "owner": "bintray", "desc": null, "system_ids": [ "io.janusproject.guava:guava" ], "versions": [ "19.0.0", "17.0.2", "17.0" ], "latest_version": "19.0.0" }, { "name": "com.google.guava:guava", "repo": "jcenter", "owner": "bintray", "desc": "Guava is a suite of core and expanded libraries that include\n utility classes, google's collections, io classes, and much\n much more.\n\n Guava has two code dependencies - javax.annotation\n per the JSR-305 spec and javax.inject per the JSR-330 spec.", "system_ids": [ "com.google.guava:guava" ], "versions": [ "19.0", "19.0-rc3", "19.0-rc2", "19.0-rc1", "18.0", "18.0-rc2", "18.0-rc1", "11.0.2-atlassian-02", "17.0", "17.0-rc2", "17.0-rc1", "16.0.1", "16.0", "16.0-rc1", "15.0", "15.0-rc1", "14.0.1", "14.0", "14.0-rc3", "14.0-rc2", "14.0-rc1", "13.0.1", "13.0", "13.0-final", "13.0-rc2", "13.0-rc1", "12.0.1", "12.0", "12.0-rc2", "12.0-rc1", "11.0.2-atlassian-01", "11.0.2", "11.0.1", "11.0", "11.0-rc1", "10.0.1", "10.0", "10.0-rc3", "10.0-rc2", "10.0-rc1", "r09", "r08", "r07", "r06", "r05", "r03" ], "latest_version": "19.0" } ] */ JsonParser parser = new JsonParser(); JsonArray array = parser.parse(response).getAsJsonArray(); int totalFound = array.size(); List<FoundArtifact> artifacts = Lists.newArrayListWithExpectedSize(totalFound); for (int i = 0; i < totalFound; i++) { JsonObject root = array.get(i).getAsJsonObject(); String name = root.getAsJsonPrimitive("name").getAsString(); List<GradleVersion> availableVersions = Lists.newArrayList(); JsonArray versions = root.getAsJsonArray("versions"); versions.forEach(element -> { String version = element.getAsString(); availableVersions.add(GradleVersion.parse(version)); }); List<String> coordinate = Splitter.on(GRADLE_PATH_SEPARATOR).splitToList(name); assert coordinate.size() == 2; artifacts.add(new FoundArtifact(getName(), coordinate.get(0), coordinate.get(1), availableVersions)); } return new SearchResult(getName(), artifacts, totalFound); }
From source file:com.apothesource.pillfill.service.drug.impl.DefaultDrugServiceImpl.java
License:Open Source License
/** * <a href="http://rxnav.nlm.nih.gov/RxNormAPIs.html#">NIH Service</a>: Get avaliable RxNorm IDs associated with an 11 digit National Drug Code (NDC). * * @param ndc The 11-digit NDC without dashes or spaces * @return A list of RxNorm IDs associated with this NDC (should normally return 0 or 1) *//*from ww w. ja va 2s .c om*/ @Override public Observable<String> getRxNormIdForDrugNdc(String ndc) { return subscribeIoObserveImmediate(subscriber -> { String urlStr = String.format(URL_RXNORM_BRAND_NAME_BY_NDC, ndc); try { String responseStr = PFNetworkManager.doPinnedGetForUrl(urlStr); JsonParser parser = new JsonParser(); JsonObject response = parser.parse(responseStr).getAsJsonObject().get("idGroup").getAsJsonObject(); if (response.has("rxnormId")) { JsonArray array = response.getAsJsonArray("rxnormId"); for (JsonElement e : array) { subscriber.onNext(e.getAsString()); } subscriber.onCompleted(); } else { Timber.e("No rxnormIds found for NDC: %s", ndc); subscriber.onError(new RuntimeException("Could not find NDC->RxNorm for NDC.")); } } catch (IOException e) { e.printStackTrace(); } }); }
From source file:com.appdynamics.monitors.boundary.BoundaryWrapper.java
License:Apache License
/** * Retrieves network traffic data in the past minute from Boundary * @param observationIds A comma separated list of valid observationIds needed to make the historical API REST request * @return responseData A JsonArray containing all the ip_addresses, and their respective network traffic metrics */// w w w . j a v a 2 s . c o m private JsonArray getResponseData(String observationIds) throws Exception { String metricsURL = constructMetricsURL(); HttpPost httpPost = new HttpPost(metricsURL); httpPost.addHeader(BasicScheme.authenticate(new UsernamePasswordCredentials(apiKey, ""), "UTF-8", false)); // Request parameters and other properties. List<NameValuePair> params = new ArrayList<NameValuePair>(2); params.add(new BasicNameValuePair("aggregations", "observationDomainId")); params.add(new BasicNameValuePair("observationDomainIds", observationIds)); Long currentTime = System.currentTimeMillis(); Long oneMinuteAgo = currentTime - 60000; params.add(new BasicNameValuePair("from", oneMinuteAgo.toString())); params.add(new BasicNameValuePair("to", currentTime.toString())); httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); HttpClient httpClient = new DefaultHttpClient(); HttpResponse response = httpClient.execute(httpPost); HttpEntity entity = response.getEntity(); BufferedReader bufferedReader2 = new BufferedReader(new InputStreamReader(entity.getContent())); StringBuilder responseString = new StringBuilder(); String line = ""; while ((line = bufferedReader2.readLine()) != null) { responseString.append(line); } JsonObject responseObject = new JsonParser().parse(responseString.toString()).getAsJsonObject(); JsonArray responseData = responseObject.getAsJsonArray("data"); return responseData; }
From source file:com.arangodb.entity.EntityDeserializers.java
License:Apache License
private static JsonObject getFirstResultAsJsonObject(JsonObject obj) { if (obj.has("result")) { if (obj.get("result").isJsonArray()) { JsonArray result = obj.getAsJsonArray("result"); if (result.size() > 0) { JsonElement jsonElement = result.get(0); if (jsonElement.isJsonObject()) { return jsonElement.getAsJsonObject(); }//w ww. j a va 2s . c om } } else if (obj.get("result").isJsonObject()) { return obj.getAsJsonObject("result"); } } return null; }
From source file:com.arangodb.entity.EntityDeserializers.java
License:Apache License
private static List<PathEntity<Object, Object>> getPaths(JsonDeserializationContext context, JsonObject visited, Class<?> vertexClazz, Class<?> edgeClazz) { List<PathEntity<Object, Object>> pathEntities = new ArrayList<PathEntity<Object, Object>>(); JsonArray paths = visited.getAsJsonArray("paths"); if (!paths.equals(null)) { for (int i = 0, imax = paths.size(); i < imax; i++) { JsonObject path = paths.get(i).getAsJsonObject(); PathEntity<Object, Object> pathEntity = new PathEntity<Object, Object>(); if (path.has("edges")) { pathEntity.setEdges(getEdges(edgeClazz, context, path.getAsJsonArray("edges"))); }// www .j a va2s . co m if (path.has("vertices")) { pathEntity.setVertices(getVertices(vertexClazz, context, path.getAsJsonArray("vertices"))); } pathEntities.add(pathEntity); } } return pathEntities; }
From source file:com.atlauncher.data.mojang.MojangArgumentsTypeAdapter.java
License:Open Source License
@Override public MojangArguments deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { List<ArgumentRule> game = new ArrayList<ArgumentRule>(); List<ArgumentRule> jvm = new ArrayList<ArgumentRule>(); final JsonObject rootJsonObject = json.getAsJsonObject(); final JsonArray gameArray = rootJsonObject.getAsJsonArray("game"); final JsonArray jvmArray = rootJsonObject.getAsJsonArray("jvm"); for (JsonElement gameArg : gameArray) { if (gameArg.isJsonObject()) { JsonObject argument = gameArg.getAsJsonObject(); game.add(Gsons.DEFAULT_ALT.fromJson(argument, ArgumentRule.class)); } else {//from ww w . j a va 2 s . c o m String argument = gameArg.getAsString(); game.add(new ArgumentRule(null, argument)); } } for (JsonElement gameArg : jvmArray) { if (gameArg.isJsonObject()) { JsonObject argument = gameArg.getAsJsonObject(); jvm.add(Gsons.DEFAULT_ALT.fromJson(argument, ArgumentRule.class)); } else { String argument = gameArg.getAsString(); jvm.add(new ArgumentRule(null, argument)); } } return new MojangArguments(game, jvm); }
From source file:com.auth0.android.lock.internal.configuration.ApplicationDeserializer.java
License:Open Source License
@Override public List<Connection> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { assertJsonObject(json);//from w w w.ja v a2 s.c o m final JsonObject object = json.getAsJsonObject(); requiredValue("id", String.class, object, context); requiredValue("tenant", String.class, object, context); requiredValue("authorize", String.class, object, context); requiredValue("callback", String.class, object, context); requiredValue("strategies", JsonArray.class, object, context); final JsonArray strategies = object.getAsJsonArray("strategies"); return mergeConnections(strategies, context); }
From source file:com.auth0.android.lock.internal.configuration.ApplicationDeserializer.java
License:Open Source License
private List<Connection> parseStrategy(JsonElement json, JsonDeserializationContext context) { final JsonObject strategy = json.getAsJsonObject(); String name = requiredValue("name", String.class, strategy, context); requiredValue("connections", Object.class, strategy, context); JsonArray connectionsArray = strategy.getAsJsonArray("connections"); List<Connection> connections = new ArrayList<>(); for (int i = 0; i < connectionsArray.size(); i++) { final JsonObject connectionJson = connectionsArray.get(i).getAsJsonObject(); requiredValue("name", String.class, connectionJson, context); Type mapType = new TypeToken<LinkedTreeMap<String, Object>>() { }.getType();/*from w w w. ja v a2s .c om*/ Map<String, Object> values = context.deserialize(connectionJson, mapType); connections.add(Connection.newConnectionFor(name, values)); } return connections; }