Java Code Examples for javax.json.JsonArray#get()
The following examples show how to use
javax.json.JsonArray#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DayCounterInfo.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * Returns an array of RoleInfo corresponding to the JSON serialization returned * by {@link QueueControl#listMessageCounterHistory()}. */ public static DayCounterInfo[] fromJSON(final String jsonString) { JsonObject json = JsonUtil.readJsonObject(jsonString); JsonArray dayCounters = json.getJsonArray("dayCounters"); DayCounterInfo[] infos = new DayCounterInfo[dayCounters.size()]; for (int i = 0; i < dayCounters.size(); i++) { JsonObject counter = (JsonObject) dayCounters.get(i); JsonArray hour = counter.getJsonArray("counters"); long[] hourCounters = new long[24]; for (int j = 0; j < 24; j++) { hourCounters[j] = hour.getInt(j); } DayCounterInfo info = new DayCounterInfo(counter.getString("date"), hourCounters); infos[i] = info; } return infos; }
Example 2
Source File: GlobalContext.java From logbook with MIT License | 6 votes |
/** * 保有艦娘を更新します * * @param data */ private static void doShipDeck(Data data) { try { JsonObject apidata = data.getJsonObject().getJsonObject("api_data"); // 艦娘を差し替える JsonArray shipData = apidata.getJsonArray("api_ship_data"); for (int i = 0; i < shipData.size(); i++) { ShipDto ship = new ShipDto((JsonObject) shipData.get(i)); ShipContext.get().put(Long.valueOf(ship.getId()), ship); } // 艦隊を設定 doDeck(apidata.getJsonArray("api_deck_data")); } catch (Exception e) { LoggerHolder.LOG.warn("保有艦娘を更新しますに失敗しました", e); LoggerHolder.LOG.warn(data); } }
Example 3
Source File: GlobalContext.java From logbook with MIT License | 6 votes |
/** * 保有艦娘を更新します * * @param data */ private static void doShip2(Data data) { try { JsonArray apidata = data.getJsonObject().getJsonArray("api_data"); // 情報を破棄 ShipContext.get().clear(); for (int i = 0; i < apidata.size(); i++) { ShipDto ship = new ShipDto((JsonObject) apidata.get(i)); ShipContext.get().put(Long.valueOf(ship.getId()), ship); } // 艦隊を設定 doDeck(data.getJsonObject().getJsonArray("api_data_deck")); addConsole("保有艦娘情報を更新しました"); } catch (Exception e) { LoggerHolder.LOG.warn("保有艦娘を更新しますに失敗しました", e); LoggerHolder.LOG.warn(data); } }
Example 4
Source File: TestContainerLog.java From rapid with MIT License | 5 votes |
@Test public void inspectContainer() { final Response listContainers = target("containers").path("json").request(MediaType.APPLICATION_JSON).get(); final JsonArray containers = listContainers.readEntity(JsonArray.class); final JsonObject container = (JsonObject) containers.get(0); final JsonString expectedId = container.getJsonString("Id"); Response log = getResponse(target("containers").path(expectedId.getString()).path("logs").queryParam("stdout", true)); assertEquals(OK.getStatusCode(), log.getStatus()); }
Example 5
Source File: GlobalContext.java From logbook with MIT License | 5 votes |
/** * 艦隊を設定します * * @param apidata */ private static void doDeck(JsonArray apidata) { dock.clear(); for (int i = 0; i < apidata.size(); i++) { JsonObject jsonObject = (JsonObject) apidata.get(i); String fleetid = Long.toString(jsonObject.getJsonNumber("api_id").longValue()); String name = jsonObject.getString("api_name"); JsonArray apiship = jsonObject.getJsonArray("api_ship"); DockDto dockdto = new DockDto(fleetid, name); dock.put(fleetid, dockdto); for (int j = 0; j < apiship.size(); j++) { Long shipid = Long.valueOf(((JsonNumber) apiship.get(j)).longValue()); ShipDto ship = ShipContext.get().get(shipid); if (ship != null) { dockdto.addShip(ship); if ((i == 0) && (j == 0)) { ShipContext.setSecretary(ship); } // 艦隊IDを設定 ship.setFleetid(fleetid); } } } }
Example 6
Source File: ChaincodeCollectionConfiguration.java From fabric-sdk-java with Apache License 2.0 | 5 votes |
Collection.CollectionConfigPackage parse(JsonArray jsonConfig) throws ChaincodeCollectionConfigurationException { Collection.CollectionConfigPackage.Builder colcofbuilder = Collection.CollectionConfigPackage.newBuilder(); for (int i = jsonConfig.size() - 1; i > -1; --i) { Collection.StaticCollectionConfig.Builder ssc = Collection.StaticCollectionConfig.newBuilder(); JsonValue j = jsonConfig.get(i); if (j.getValueType() != JsonValue.ValueType.OBJECT) { throw new ChaincodeCollectionConfigurationException(format("Expected StaticCollectionConfig to be Object type but got: %s", j.getValueType().name())); } JsonObject jsonObject = j.asJsonObject(); JsonObject scf = getJsonObject(jsonObject, "StaticCollectionConfig"); // oneof .. may have different values in the future ssc.setName(getJsonString(scf, "name")) .setBlockToLive(getJsonLong(scf, "blockToLive")) .setMaximumPeerCount(getJsonInt(scf, "maximumPeerCount")) .setMemberOrgsPolicy(Collection.CollectionPolicyConfig.newBuilder() .setSignaturePolicy(parseSignaturePolicyEnvelope(scf)).build()) .setRequiredPeerCount(getJsonInt(scf, "requiredPeerCount")); colcofbuilder.addConfig(Collection.CollectionConfig.newBuilder().setStaticCollectionConfig(ssc).build()); } return colcofbuilder.build(); }
Example 7
Source File: TestContainerInspect.java From rapid with MIT License | 5 votes |
@Test public void inspectContainer() { final Response listContainers = target("containers").path("json").request(MediaType.APPLICATION_JSON).get(); final JsonArray containers = listContainers.readEntity(JsonArray.class); final JsonObject container = (JsonObject) containers.get(0); final JsonString expectedId = container.getJsonString("Id"); Response inspect = getResponse(target("containers").path(expectedId.getString()).path("json")); assertEquals(200, inspect.getStatus()); final JsonObject actualContainer = inspect.readEntity(JsonObject.class); assertEquals(expectedId.getString(), actualContainer.getJsonString("Id").getString()); }
Example 8
Source File: CadfReporterStep.java From FHIR with Apache License 2.0 | 5 votes |
public static CadfReporterStep parse(JsonObject jsonObject) throws FHIRException, IOException, ClassNotFoundException { CadfReporterStep.Builder builder = CadfReporterStep.builder(); if (jsonObject.get("reporter") != null) { JsonObject reporter = jsonObject.getJsonObject("reporter"); CadfResource resource = CadfResource.Parser.parse(reporter); builder.reporter(resource); } if (jsonObject.get("reporterId") != null) { String reporterId = jsonObject.getString("reporterId"); builder.reporterId(reporterId); } if (jsonObject.get("reporterTime") != null) { String rTime = jsonObject.getString("reporterTime"); TemporalAccessor reporterTime = DATE_TIME_PARSER_FORMATTER.parse(rTime); builder.reporterTime(ZonedDateTime.from(reporterTime)); } if (jsonObject.get("role") != null) { String role = jsonObject.getString("role"); builder.role(ReporterRole.valueOf(role)); } if (jsonObject.get("attachments") != null) { JsonArray annotations = jsonObject.getJsonArray("attachments"); for (int i = 0; i < annotations.size(); i++) { JsonObject obj = (JsonObject) annotations.get(0); CadfAttachment item = CadfAttachment.Parser.parse(obj); builder.attachment(item); } } return builder.build(); }
Example 9
Source File: TestContainerTop.java From rapid with MIT License | 5 votes |
@Test public void inspectContainer() { final Response listContainers = getResponse(target("containers").path("json")); final JsonArray containers = listContainers.readEntity(JsonArray.class); final JsonObject container = (JsonObject) containers.get(0); final JsonString expectedId = container.getJsonString("Id"); Response top = getResponse(target("containers").path(expectedId.getString()).path("top")); assertEquals(200, top.getStatus()); final JsonObject actualContainer = top.readEntity(JsonObject.class); int expectedProcessSize = 1; assertEquals(expectedProcessSize, actualContainer.getJsonArray("Processes").size()); }
Example 10
Source File: JSONContentHandler.java From jcypher with Apache License 2.0 | 5 votes |
@Override public Object convertContentValue(Object value) { if (value instanceof JsonValue) { JsonValue val = (JsonValue) value; Object ret = null; ValueType typ = val.getValueType(); if (typ == ValueType.NUMBER) ret = ((JsonNumber)val).bigDecimalValue(); else if (typ == ValueType.STRING) ret = ((JsonString)val).getString(); else if (typ == ValueType.FALSE) ret = Boolean.FALSE; else if (typ == ValueType.TRUE) ret = Boolean.TRUE; else if (typ == ValueType.ARRAY) { JsonArray arr = (JsonArray)val; List<Object> vals = new ArrayList<Object>(); int sz = arr.size(); for (int i = 0; i < sz; i++) { JsonValue v = arr.get(i); vals.add(convertContentValue(v)); } ret = vals; } else if (typ == ValueType.OBJECT) { //JsonObject obj = (JsonObject)val; } return ret; } return value; }
Example 11
Source File: ReportMerger.java From KITE with Apache License 2.0 | 5 votes |
private static void fixWrongStatus(String pathToReportFolder) throws IOException { File reportFolder = new File(pathToReportFolder); File[] subFiles = reportFolder.listFiles(); for (int index = 0; index < subFiles.length; index++) { if (subFiles[index].getName().contains("result.json")) { JsonObject result = readJsonFile(subFiles[index].getAbsolutePath()); JsonObject statusDetail = result.getJsonObject("statusDetails"); String message = statusDetail.getString("message"); boolean issue = message.equalsIgnoreCase("The test has passed successfully!") && !result.getString("status").equals("PASSED"); if (issue) { JsonArray steps = result.getJsonArray("steps"); for (int i = 0; i < steps.size(); i++) { JsonObject step = (JsonObject)steps.get(i); if (!step.getString("status").equals("PASSED")){ statusDetail = step.getJsonObject("statusDetails"); break; } } JsonObjectBuilder builder = Json.createObjectBuilder(); for (String key: result.keySet()) { if (!key.equals("statusDetails")) { builder.add(key, result.get(key)); } else { builder.add(key, statusDetail); } } FileUtils.forceDelete(new File(subFiles[index].getAbsolutePath())); printJsonTofile(builder.build().toString(), subFiles[index].getAbsolutePath()); } } } }
Example 12
Source File: GraphQLVariables.java From smallrye-graphql with Apache License 2.0 | 5 votes |
private Object toObject(JsonValue jsonValue) { Object ret = null; JsonValue.ValueType typ = jsonValue.getValueType(); if (null != typ) switch (typ) { case NUMBER: ret = ((JsonNumber) jsonValue).bigDecimalValue(); break; case STRING: ret = ((JsonString) jsonValue).getString(); break; case FALSE: ret = Boolean.FALSE; break; case TRUE: ret = Boolean.TRUE; break; case ARRAY: JsonArray arr = (JsonArray) jsonValue; List<Object> vals = new ArrayList<>(); int sz = arr.size(); for (int i = 0; i < sz; i++) { JsonValue v = arr.get(i); vals.add(toObject(v)); } ret = vals; break; case OBJECT: ret = toMap((JsonObject) jsonValue); break; default: break; } return ret; }
Example 13
Source File: JsonSupport.java From FHIR with Apache License 2.0 | 5 votes |
public static JsonValue getJsonValue(JsonArray jsonArray, int index) { if (jsonArray != null) { if (index >= 0 && index < jsonArray.size()) { return jsonArray.get(index); } else { throw new IllegalArgumentException("Could not find element at index: " + index); } } return null; }
Example 14
Source File: CadfMetric.java From FHIR with Apache License 2.0 | 5 votes |
public static CadfMetric parse(JsonObject jsonObject) throws FHIRException, IOException { CadfMetric.Builder builder = CadfMetric.builder(); String name = jsonObject.getString("name"); if (name != null) { builder.name(name); } String unit = jsonObject.getString("unit"); if (unit != null) { builder.unit(unit); } String metricId = jsonObject.getString("metricId"); if (metricId != null) { builder.metricId(metricId); } JsonArray annotations = jsonObject.getJsonArray("annotations"); if (annotations != null) { for (int i = 0; i < annotations.size(); i++) { JsonObject obj = (JsonObject) annotations.get(0); CadfMapItem mapItem = CadfMapItem.Parser.parse(obj); builder.annotation(mapItem); } } return builder.build(); }
Example 15
Source File: JsTestRunner.java From KITE with Apache License 2.0 | 4 votes |
private AllureStepReport processResult(String workingDir, JsonObject result) throws KiteTestException { String path = workingDir + this.reportPath + "/" + id + "/"; if (result != null) { String status = result.getString("status", "passed"); this.reports.get(this.stepPhase).setStatus(Status.fromValue(status)); // Step report AllureStepReport stepReport = null; JsonArray steps = result.getJsonArray("steps"); for (int i = 0; i < steps.size(); i++) { JsonObject idx = (JsonObject) steps.get(i); stepReport = new AllureStepReport(idx.getString("name", "place holder")); String stepStatus = idx.getString("status", "passed"); stepReport.setStatus((Status.fromValue(stepStatus))); stepReport.setStartTimestamp((long) idx.getInt("start")); stepReport.setStopTimestamp((long) idx.getInt("stop")); if(idx.containsKey("statusDetails")) { JsonObject details = idx.getJsonObject("statusDetails"); StatusDetails statusDetails = new StatusDetails(); statusDetails.setMessage(details.getString("message")); statusDetails.setKnown(details.getBoolean("known")); statusDetails.setFlaky(details.getBoolean("flaky")); statusDetails.setMuted(details.getBoolean("muted")); stepReport.setDetails(statusDetails); } if (idx.get("attachments") != null) { JsonArray attachmentsObj = (JsonArray) idx.get("attachments"); for (int j = 0; j < attachmentsObj.size(); j++) { JsonObject attachmentJSON = (JsonObject) attachmentsObj.get(j); String attachmentSource = (String) attachmentJSON.getString("source"); // To recover file extension String extension = attachmentSource.substring(attachmentSource.lastIndexOf(".")).replace(".", ""); try { if (!extension.equals("png")) { String text = TestUtils.readFile(path + attachmentSource); String name = attachmentJSON.getString("name"); reporter.textAttachment(stepReport, name, text, extension); } else { reporter.screenshotAttachment(stepReport, "Screenshot", Files.readAllBytes(Paths.get(path + "/screenshots/" + attachmentSource))); } } catch (IOException e) { throw new KiteTestException("Error reading the report generated in javascript", Status.BROKEN, e); } } } JsonArray childSteps = idx.getJsonArray("steps"); for (int k = 0; k < childSteps.size(); k++) { JsonObject child = (JsonObject) childSteps.get(k); stepReport.addStepReport(processResult(workingDir, child)); } this.reports.get(this.stepPhase).addStepReport(stepReport); } return stepReport; } throw new KiteTestException("There's a null value in the report", Status.BROKEN); }
Example 16
Source File: GlobalContext.java From logbook with MIT License | 4 votes |
/** * 建造(入手)情報を更新します * @param data */ private static void doGetship(Data data) { try { JsonObject apidata = data.getJsonObject().getJsonObject("api_data"); String dock = data.getField("api_kdock_id"); // 艦娘の装備を追加します if (!apidata.isNull("api_slotitem")) { JsonArray slotitem = apidata.getJsonArray("api_slotitem"); for (int i = 0; i < slotitem.size(); i++) { JsonObject object = (JsonObject) slotitem.get(i); int typeid = object.getJsonNumber("api_slotitem_id").intValue(); Long id = object.getJsonNumber("api_id").longValue(); ItemDto item = Item.get(typeid); if (item != null) { ItemContext.get().put(id, item); } } } // 艦娘を追加します JsonObject apiShip = apidata.getJsonObject("api_ship"); ShipDto ship = new ShipDto(apiShip); ShipContext.get().put(Long.valueOf(ship.getId()), ship); // 投入資源を取得する ResourceDto resource = getShipResource.get(dock); if (resource == null) { resource = KdockConfig.load(dock); } GetShipDto dto = new GetShipDto(ship, resource); getShipList.add(dto); CreateReportLogic.storeCreateShipReport(dto); // 投入資源を除去する getShipResource.remove(dock); KdockConfig.remove(dock); addConsole("建造(入手)情報を更新しました"); } catch (Exception e) { LoggerHolder.LOG.warn("建造(入手)情報を更新しますに失敗しました", e); LoggerHolder.LOG.warn(data); } }
Example 17
Source File: JSONContentHandler.java From jcypher with Apache License 2.0 | 4 votes |
private JsonValue getRestValue(JsonArray restArray, int colIdx) { return restArray.get(colIdx); }
Example 18
Source File: ArtemisFeatureTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test(timeout = 5 * 60 * 1000) public void test() throws Throwable { executeCommand("bundle:list"); withinReason(new Callable<Boolean>() { @Override public Boolean call() throws Exception { assertTrue("artemis bundle installed", verifyBundleInstalled("artemis-server-osgi")); return true; } }); Object service = waitForService("(objectClass=org.apache.activemq.artemis.core.server.ActiveMQServer)", 30000); assertNotNull(service); log.debug("have service " + service); executeCommand("service:list -n"); Connection connection = null; try { JmsConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:5672"); connection = factory.createConnection(USER, PASSWORD); connection.start(); QueueSession sess = (QueueSession) connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); Queue queue = sess.createQueue("exampleQueue"); MessageProducer producer = sess.createProducer(queue); producer.send(sess.createTextMessage("TEST")); // Test browsing try (QueueBrowser browser = sess.createBrowser(queue)) { Enumeration messages = browser.getEnumeration(); while (messages.hasMoreElements()) { messages.nextElement(); } } // Test management Queue managementQueue = sess.createQueue("activemq.management"); QueueRequestor requestor = new QueueRequestor(sess, managementQueue); connection.start(); TextMessage m = sess.createTextMessage(); m.setStringProperty("_AMQ_ResourceName", "broker"); m.setStringProperty("_AMQ_OperationName", "getQueueNames"); m.setText("[\"ANYCAST\"]"); Message reply = requestor.request(m); String json = ((TextMessage) reply).getText(); JsonArray array = Json.createReader(new StringReader(json)).readArray(); List<JsonString> queues = (List<JsonString>) array.get(0); assertNotNull(queues); assertFalse(queues.isEmpty()); MessageConsumer consumer = sess.createConsumer(queue); Message msg = consumer.receive(5000); assertNotNull(msg); } finally { if (connection != null) { connection.close(); } } }
Example 19
Source File: QueueControlTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
protected long getFirstMessageId(final QueueControl queueControl) throws Exception { JsonArray array = JsonUtil.readJsonArray(queueControl.getFirstMessageAsJSON()); JsonObject object = (JsonObject) array.get(0); return object.getJsonNumber("messageID").longValue(); }
Example 20
Source File: CadfGeolocation.java From FHIR with Apache License 2.0 | 4 votes |
public static CadfGeolocation parse(JsonObject jsonObject) throws FHIRException, IOException { CadfGeolocation.Builder builder = CadfGeolocation.builder(); if (jsonObject.get("id") != null) { String id = jsonObject.getString("id"); builder.id(id); } if (jsonObject.get("latitude") != null) { String latitude = jsonObject.getString("latitude"); builder.latitude(latitude); } if (jsonObject.get("longitude") != null) { String longitude = jsonObject.getString("longitude"); builder.longitude(longitude); } if (jsonObject.get("elevation") != null) { BigDecimal elevation = jsonObject.getJsonNumber("elevation").bigDecimalValue(); builder.elevation(elevation.doubleValue()); } if (jsonObject.get("accuracy") != null) { BigDecimal accuracy = jsonObject.getJsonNumber("accuracy").bigDecimalValue(); builder.accuracy(accuracy.doubleValue()); } if (jsonObject.get("city") != null) { String city = jsonObject.getString("city"); builder.city(city); } if (jsonObject.get("state") != null) { String state = jsonObject.getString("state"); builder.state(state); } if (jsonObject.get("region") != null) { String region = jsonObject.getString("region"); builder.region(region); } if (jsonObject.get("annotations") != null) { JsonArray annotations = jsonObject.getJsonArray("annotations"); for (int i = 0; i < annotations.size(); i++) { JsonObject obj = (JsonObject) annotations.get(0); CadfMapItem mapItem = CadfMapItem.Parser.parse(obj); builder.addAnnotation(mapItem); } } return builder.build(); }