List of usage examples for com.google.gson JsonObject getAsJsonArray
public JsonArray getAsJsonArray(String memberName)
From source file:citysdk.tourism.client.parser.POIDeserializer.java
License:Open Source License
private void getLocation(POI poi, JsonObject jObject) { JsonObject json = jObject.getAsJsonObject(LOCATION); JsonArray array;/* ww w. j a va 2 s . c o m*/ Location location = new Location(); if (json.has(POINT)) { array = json.getAsJsonArray(POINT); getPoints(location, array); } if (json.has(LINE)) { array = json.getAsJsonArray(LINE); getLine(location, array); } if (json.has(POLYGON)) { array = json.getAsJsonArray(POLYGON); getSimplePolygon(location, array); } if (json.has(ADDRESS)) location.setAddress(getPOIBaseType(json.getAsJsonObject(ADDRESS))); if (json.has(RELATIONSHIP)) { array = json.getAsJsonArray(RELATIONSHIP); getRelationships(location, array); } poi.setLocation(location); }
From source file:citysdk.tourism.client.parser.POIDeserializer.java
License:Open Source License
private void getTime(POI poi, JsonObject jObject) { JsonArray jArray = jObject.getAsJsonArray(TIME); for (int i = 0; i < jArray.size(); i++) { JsonObject ob = jArray.get(i).getAsJsonObject(); POITermType term = getPOITermType(ob); if (ob.has(SCHEME)) term.setScheme(ob.get(SCHEME).getAsString()); poi.addTime(term);//from w ww . jav a 2 s . com } }
From source file:citysdk.tourism.client.parser.POIDeserializer.java
License:Open Source License
private void getLinks(POI poi, JsonObject jObject) { JsonArray jArray = jObject.getAsJsonArray(LINK); for (int i = 0; i < jArray.size(); i++) { JsonObject ob = jArray.get(i).getAsJsonObject(); POITermType term = getPOITermType(ob); poi.addLink(term);//from ww w . j a v a 2s.c om } }
From source file:classes.analysis.Analysis.java
License:Open Source License
private static Analysis parseAnalysisGalaxyData(String origin, String emsuser, JsonObject analysisData) { JsonParser parser = new JsonParser(); JsonArray provenance = (JsonArray) parser.parse(analysisData.get("provenance").getAsString()); //STEP 1. Find the associations between the steps (inputs and outputs) HashMap<String, JsonElement> outputs = new HashMap<String, JsonElement>(); JsonObject stepJSONobject; for (JsonElement step_json : provenance) { stepJSONobject = step_json.getAsJsonObject(); for (JsonElement output : stepJSONobject.getAsJsonArray("outputs")) { outputs.put(output.getAsJsonObject().get("id").getAsString(), step_json); }//from w ww . j a va 2s .c o m if ("upload1".equalsIgnoreCase(stepJSONobject.get("tool_id").getAsString())) { stepJSONobject.remove("step_type"); stepJSONobject.add("step_type", new JsonPrimitive("external_source")); } else { stepJSONobject.add("step_type", new JsonPrimitive("processed_data")); } } for (JsonElement step_json : provenance) { stepJSONobject = step_json.getAsJsonObject(); for (JsonElement input : stepJSONobject.getAsJsonArray("inputs")) { String id = input.getAsJsonObject().get("id").getAsString(); if (outputs.containsKey(id)) { if (!"external_source" .equalsIgnoreCase(outputs.get(id).getAsJsonObject().get("step_type").getAsString())) { outputs.get(id).getAsJsonObject().remove("step_type"); outputs.get(id).getAsJsonObject().add("step_type", new JsonPrimitive("intermediate_data")); } if (!stepJSONobject.has("used_data")) { stepJSONobject.add("used_data", new JsonArray()); } ((JsonArray) stepJSONobject.get("used_data")).add(new JsonPrimitive( "STxxxx." + outputs.get(id).getAsJsonObject().get("id").getAsString())); } } } //STEP 2. Create the instances for the steps ArrayList<NonProcessedData> nonProcessedDataList = new ArrayList<NonProcessedData>(); ArrayList<ProcessedData> processedDataList = new ArrayList<ProcessedData>(); for (JsonElement step_json : provenance) { stepJSONobject = step_json.getAsJsonObject(); if ("external_source".equalsIgnoreCase(stepJSONobject.get("step_type").getAsString())) { nonProcessedDataList.add(ExternalData.parseStepGalaxyData(stepJSONobject, analysisData, emsuser)); } else if ("intermediate_data".equalsIgnoreCase(stepJSONobject.get("step_type").getAsString())) { nonProcessedDataList .add(IntermediateData.parseStepGalaxyData(stepJSONobject, analysisData, emsuser)); } else if ("processed_data".equalsIgnoreCase(stepJSONobject.get("step_type").getAsString())) { processedDataList.add(ProcessedData.parseStepGalaxyData(stepJSONobject, analysisData, emsuser)); } else { throw new InstantiationError("Unknown step type"); } } Collections.sort(nonProcessedDataList); Collections.sort(processedDataList); //STEP 3. Create the instance of analysis Analysis analysis = new Analysis(); analysis.setAnalysisName(analysisData.get("ems_analysis_name").getAsString()); analysis.setAnalysisType("Galaxy workflow"); analysis.setNonProcessedData(nonProcessedDataList.toArray(new NonProcessedData[] {})); analysis.setProcessedData(processedDataList.toArray(new ProcessedData[] {})); analysis.setTags(new String[] { "imported" }); analysis.setStatus("pending"); return analysis; }
From source file:cloudlens.parser.ASTBuilder.java
License:Apache License
public static List<ASTParagraph> parseZeppelinExport(String file) throws FileNotFoundException, IOException { final List<ASTParagraph> res = new ArrayList<>(); try (final FileReader rd = new FileReader(file);) { final JsonObject notebook = new JsonParser().parse(rd).getAsJsonObject(); final JsonArray paragraphs = notebook.getAsJsonArray("paragraphs"); final Iterator<JsonElement> it = paragraphs.iterator(); while (it.hasNext()) { final JsonObject p = it.next().getAsJsonObject(); final JsonPrimitive textOpt = p.getAsJsonPrimitive("text"); if (textOpt != null) { final String text = textOpt.getAsString(); if (text.startsWith("%cl")) { final String content = text.substring(3); final List<ASTElement> elements = parse(content); res.add(new ASTParagraph(elements)); } else { res.add(new ASTParagraph(text)); }/*from w w w . j a v a 2 s .co m*/ } } } return res; }
From source file:co.edu.poli.util.jqgrid.JqGridData.java
public void getJsonObject(String j) { /*String j = "{groupOp:OR,rules:[{field:id_encabezado,op:cn,data:prueba}," + "{field:modulo,op:cn,data:prueba}," + "{field:norma,op:cn,data:prueba}," + "{field:resultado,op:cn,data:prueba}," + "{field:evidencia,op:cn,data:prueba}," + "{field:elemento,op:cn,data:prueba}," + "{field:descripcion_encab,op:cn,data:prueba98}]}";*/ filtersArr = new HashMap(); Gson gson = new Gson(); JsonElement jelement = new JsonParser().parse(j); JsonObject jobject = jelement.getAsJsonObject(); filtersArr.put("groupOp", jobject.get("groupOp")); JsonArray array = jobject.getAsJsonArray("rules"); ArrayList<filter> f = new ArrayList<>(); for (int i = 0; i < array.size(); i++) { {/*from w w w . j av a 2 s . c o m*/ JsonObject cont = array.get(i).getAsJsonObject(); f.add(new filter(cont.get("field").getAsString(), cont.get("op").getAsString(), cont.get("data").getAsString())); } } filtersArr.put("rules", f); // System.out.println(System.out.printf(searchOperation.get("cn").toString(),"oscar","mesa").toString()); }
From source file:com.adobe.acs.commons.exporters.impl.users.Parameters.java
License:Apache License
public Parameters(SlingHttpServletRequest request) throws IOException { final JsonObject json = new JsonParser().parse(request.getParameter("params")).getAsJsonObject(); final List<String> tmpCustomProperties = new ArrayList<String>(); final List<String> tmpGroups = new ArrayList<String>(); groupFilter = getString(json, GROUP_FILTER); JsonArray groupsJSON = json.getAsJsonArray(GROUPS); for (int i = 0; i < groupsJSON.size(); i++) { tmpGroups.add(groupsJSON.get(i).getAsString()); }//from w w w . j a va2s . c om this.groups = tmpGroups.toArray(new String[tmpGroups.size()]); JsonArray customPropertiesJSON = json.getAsJsonArray(CUSTOM_PROPERTIES); for (int i = 0; i < customPropertiesJSON.size(); i++) { JsonObject tmp = customPropertiesJSON.get(i).getAsJsonObject(); if (tmp.has(RELATIVE_PROPERTY_PATH)) { String relativePropertyPath = getString(tmp, RELATIVE_PROPERTY_PATH); tmpCustomProperties.add(relativePropertyPath); } } this.customProperties = tmpCustomProperties.toArray(new String[tmpCustomProperties.size()]); }
From source file:com.adobe.acs.commons.workflow.bulk.removal.impl.servlets.RemoveServlet.java
License:Apache License
@Override public final void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); List<String> statuses = new ArrayList<>(); List<String> models = new ArrayList<>(); List<Pattern> payloads = new ArrayList<>(); Calendar olderThan = null;/*from ww w . j a v a2 s .c o m*/ try { JsonObject params = toJsonObject(request.getParameter("params")); JsonArray jsonArray = params.getAsJsonArray(PARAM_WORKFLOW_STATUSES); for (int i = 0; i < jsonArray.size(); i++) { statuses.add(jsonArray.get(i).getAsString()); } jsonArray = params.getAsJsonArray(PARAM_WORKFLOW_MODELS); for (int i = 0; i < jsonArray.size(); i++) { models.add(jsonArray.get(i).getAsString()); } jsonArray = params.getAsJsonArray(PARAM_WORKFLOW_PAYLOADS); for (int i = 0; i < jsonArray.size(); i++) { final JsonObject tmp = jsonArray.get(i).getAsJsonObject(); final String pattern = getString(tmp, "pattern"); if (StringUtils.isNotBlank(pattern)) { payloads.add(Pattern.compile(pattern)); } } final Long ts = getLong(params, PARAM_OLDER_THAN); if (ts != null && ts > 0) { olderThan = Calendar.getInstance(); olderThan.setTimeInMillis(ts * MS_IN_SECOND); } int batchSize = getInteger(params, PARAM_BATCH_SIZE); if (batchSize < 1) { batchSize = DEFAULT_BATCH_SIZE; } int maxDuration = getInteger(params, PARAM_MAX_DURATION); if (maxDuration < 1) { maxDuration = DEFAULT_MAX_DURATION; } workflowInstanceRemover.removeWorkflowInstances(request.getResourceResolver(), models, statuses, payloads, olderThan, batchSize, maxDuration); } catch (WorkflowRemovalForceQuitException e) { response.setStatus(599); response.getWriter().write("Workflow removal force quit"); } catch (Exception e) { log.error("An error occurred while attempting to remove workflow instances.", e); response.setStatus(SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR); if (response.getWriter() != null) { response.getWriter().write(e.getMessage()); } } }
From source file:com.agateau.pixelwheels.stats.JsonGameStatsIO.java
License:Open Source License
private void loadTrackStats(TrackStats trackStats, JsonObject object) { loadResults(trackStats.mLapRecords, object.getAsJsonArray("lap")); loadResults(trackStats.mTotalRecords, object.getAsJsonArray("total")); }
From source file:com.agwego.common.GsonHelper.java
License:Open Source License
/** * Short hand, check if the object is not null and the key is presence return the result as a JsonArray * * @param jObject the JsonObject in question * @param key the key to lookup//from w w w . j a va2s . co m * @return the JsonArray for this key or a new empty JsonArray */ public static JsonArray getAsArray(final JsonObject jObject, final String key) { if (jObject != null && jObject.has(key)) { try { return jObject.getAsJsonArray(key); } catch (ClassCastException ex) { // fall through } } return new JsonArray(); }