List of usage examples for javax.json JsonArray getJsonNumber
JsonNumber getJsonNumber(int index);
From source file:com.buffalokiwi.aerodrome.jet.Utils.java
/** * Convert a json array to a list of integers. * if arr is null, then an empty List<Integer> instance is returned. * /*from w w w.j av a2s .c o m*/ * This is more safe than JsonArray.getValuesAs() as this method * has built-in type checking and will throw a ClassCastException if * the type is incorrect or null. * * @param arr array * @return a list * @throws ClassCastException if any element in arr is not an integer */ public static List<Long> jsonArrayToLongList(final JsonArray arr) { final List<Long> out = new ArrayList<>(); if (arr == null) return out; for (int i = 0; i < arr.size(); i++) { final long j = Utils.getJsonNumber(arr.getJsonNumber(i)).longValue(); out.add(j); } return out; }
From source file:io.hops.hopsworks.common.util.WebCommunication.java
public List<NodesTableItem> getNdbinfoNodesTable(String hostAddress, String agentPassword) throws GenericException { List<NodesTableItem> resultList = new ArrayList<NodesTableItem>(); String url = createUrl("mysql", hostAddress, "ndbinfo", "nodes"); String jsonString = fetchContent(url, agentPassword); InputStream stream = new ByteArrayInputStream(jsonString.getBytes(StandardCharsets.UTF_8)); try {//from w ww .ja va2 s. co m JsonArray json = Json.createReader(stream).readArray(); if (json.get(0).equals("Error")) { resultList.add(new NodesTableItem(null, json.getString(1), null, null, null)); return resultList; } for (int i = 0; i < json.size(); i++) { JsonArray node = json.getJsonArray(i); Integer nodeId = node.getInt(0); Long uptime = node.getJsonNumber(1).longValue(); String status = node.getString(2); Integer startPhase = node.getInt(3); Integer configGeneration = node.getInt(4); resultList.add(new NodesTableItem(nodeId, status, uptime, startPhase, configGeneration)); } } catch (Exception ex) { logger.log(Level.SEVERE, "Exception: {0}", ex); resultList.add(new NodesTableItem(null, "Error", null, null, null)); } return resultList; }