List of usage examples for com.google.gson JsonArray get
public JsonElement get(int i)
From source file:catalog.CloudantUtil.java
License:Apache License
public static JsonArray addDeletedPropertyToDocs(JsonArray docs) { for (int i = 0; i < docs.size(); i++) { JsonElement id = docs.get(i).getAsJsonObject().get("id"); JsonElement rev = docs.get(i).getAsJsonObject().get("rev"); docs.get(i).getAsJsonObject().add("_id", id); docs.get(i).getAsJsonObject().add("_rev", rev); docs.get(i).getAsJsonObject().addProperty("_deleted", true); }/*from ww w . j av a 2s . co m*/ return docs; }
From source file:ccm.pay2spawn.util.JsonNBTHelper.java
License:Open Source License
public static NBTTagByteArray parseJSONByteArray(String value) { JsonArray in = JSON_PARSER.parse(value).getAsJsonArray(); byte[] out = new byte[in.size()]; for (int i = 0; i < in.size(); i++) out[i] = in.get(i).getAsByte(); return new NBTTagByteArray(out); }
From source file:ccm.pay2spawn.util.JsonNBTHelper.java
License:Open Source License
public static NBTTagIntArray parseJSONIntArray(String value) { JsonArray in = JSON_PARSER.parse(value).getAsJsonArray(); int[] out = new int[in.size()]; for (int i = 0; i < in.size(); i++) out[i] = in.get(i).getAsInt(); return new NBTTagIntArray(out); }
From source file:ch.cern.db.flume.source.deserializer.RecoveryManagerDeserializer.java
License:GNU General Public License
/** * Reads a line from a file and returns an event * //from ww w.ja v a 2s . co m * @return Event containing parsed line * @throws IOException */ @Override public Event readEvent() throws IOException { ensureOpen(); in.mark(); if (in.read() == -1) return null; in.reset(); RecoveryManagerLogFile rman_log = new RecoveryManagerLogFile(in, maxLineLength); JSONEvent event = new JSONEvent(); event.addProperty("startTimestamp", rman_log.getStartTimestamp()); event.addProperty("backupType", rman_log.getBackupType()); event.addProperty("destination", rman_log.getBackupDestination()); event.addProperty("entityName", rman_log.getEntityName()); //Process properties like (name = value) for (Pair<String, String> property : rman_log.getProperties()) event.addProperty(property.getFirst(), property.getSecond()); String v_params = rman_log.getVParams(); event.addProperty("v_params", v_params != null ? new JsonParser().parse(v_params).getAsJsonObject() : null); JsonArray mountPointNASRegexResult = rman_log.getMountPointNASRegexResult(); event.addProperty("mountPointNASRegexResult", mountPointNASRegexResult); JsonArray volInfoBackuptoDiskFinalResult = rman_log.getVolInfoBackuptoDiskFinalResult(); event.addProperty("volInfoBackuptoDiskFinalResult", volInfoBackuptoDiskFinalResult); JsonArray valuesOfFilesystems = rman_log.getValuesOfFilesystems(); event.addProperty("valuesOfFilesystems", valuesOfFilesystems); List<RecoveryManagerReport> recoveryManagerReports = rman_log.getRecoveryManagerReports(); JsonArray recoveryManagerReportsJson = recoveryManagerReportsToJSON(recoveryManagerReports); event.addProperty("recoveryManagerReports", recoveryManagerReportsJson); int recoveryManagerReportsSize = recoveryManagerReportsJson.size(); if (recoveryManagerReportsSize > 0) { JsonObject lastReport = (JsonObject) recoveryManagerReportsJson.get(recoveryManagerReportsSize - 1); event.addProperty("finishTime", lastReport.get("finishTime")); event.addProperty("finalStatus", lastReport.get("status")); } else { event.addProperty("finishTime", null); event.addProperty("finalStatus", null); } return event; }
From source file:ch.there.gson.GsonInvokerServiceExporter.java
License:Apache License
@Override public void handle(HttpExchange exchange) throws IOException { Gson gson = GsonFactory.getGson();//from w w w . j ava2 s.c om try { Integer rpcVersion = Integer.valueOf(exchange.getRequestHeaders().getFirst("rpc-version")); CallerRemoteApiVersion.setVersion(rpcVersion); InputStreamReader reader = new InputStreamReader(exchange.getRequestBody()); JsonParser parser = new JsonParser(); JsonObject remote = parser.parse(reader).getAsJsonObject(); String methodName = remote.get("methodName").getAsString(); Type collectionType = new TypeToken<Collection<Class<?>>>() { }.getType(); Collection<Class<?>> parameterTypes = gson.fromJson(remote.get("parameterTypes"), collectionType); JsonArray args = remote.get("arguments").getAsJsonArray(); Class<?>[] params = parameterTypes.toArray(new Class[parameterTypes.size()]); Object[] arguments = new Object[params.length]; for (int i = 0; i < params.length; i++) { Class<?> clazz = params[i]; Object argument = gson.fromJson(args.get(i), clazz); arguments[i] = argument; } RemoteInvocation remoteInvocation = new RemoteInvocation(methodName, params, arguments); RemoteInvocationResult result = invokeAndCreateResult(remoteInvocation, getProxy()); writeRemoteInvocationResult(exchange, result); exchange.close(); } catch (Throwable e) { e.printStackTrace(); } }
From source file:citysdk.tourism.client.parser.POIDeserializer.java
License:Open Source License
private void getLabels(POI poi, JsonObject jObject) { JsonArray jArray = jObject.getAsJsonArray(LABEL); for (int i = 0; i < jArray.size(); i++) { JsonElement e = jArray.get(i); JsonObject o = e.getAsJsonObject(); poi.addLabel(getPOITermType(o)); }/*from w ww . j a va2s . c o m*/ }
From source file:citysdk.tourism.client.parser.POIDeserializer.java
License:Open Source License
private void getDescription(POI poi, JsonObject jObject) { JsonArray jArray = jObject.getAsJsonArray(DESCRIPTION); for (int i = 0; i < jArray.size(); i++) { JsonElement e = jArray.get(i); JsonObject o = e.getAsJsonObject(); poi.addDescription(getPOIBaseType(o)); }//www. ja v a 2 s.c o m }
From source file:citysdk.tourism.client.parser.POIDeserializer.java
License:Open Source License
private void getCategories(POI poi, JsonObject jObject) { JsonArray jArray = jObject.getAsJsonArray(CATEGORY); for (int i = 0; i < jArray.size(); i++) { JsonElement e = jArray.get(i); JsonObject o = e.getAsJsonObject(); poi.addCategory(getPOITermType(o)); }/* ww w .j a v a 2 s . c o m*/ }
From source file:citysdk.tourism.client.parser.POIDeserializer.java
License:Open Source License
private void getPoints(Location location, JsonArray array) { for (int i = 0; i < array.size(); i++) { JsonObject ob = array.get(i).getAsJsonObject(); Geometry g = new Geometry(); g.setPosList(ob.get(POINT_P).getAsJsonObject().get(POS_LIST).getAsString()); Point point = new Point(); point.setTerm(ob.get(TERM).getAsString()); point.setPoint(g);// ww w . ja v a 2 s. co m location.addPoint(point); } }
From source file:citysdk.tourism.client.parser.POIDeserializer.java
License:Open Source License
private void getLine(Location location, JsonArray array) { for (int i = 0; i < array.size(); i++) { JsonObject ob = array.get(i).getAsJsonObject(); Geometry g = new Geometry(); g.setPosList(ob.get(LINE_STRING).getAsJsonObject().get(POS_LIST).getAsString()); Line line = new Line(); line.setTerm(ob.get(TERM).getAsString()); line.setLineString(g);//from ww w . j av a 2s . c o m location.addLine(line); } }