List of usage examples for com.fasterxml.jackson.databind JsonNode size
public int size()
From source file:org.lendingclub.mercator.newrelic.NewRelicClientImpl.java
@Override public ObjectNode getApplications() { ObjectNode appsNode = mapper.createObjectNode(); List<JsonNode> applicationsList = new ArrayList<JsonNode>(); int page = 1; JsonNode apps = getApplications(page); while (apps.size() != 0) { List<JsonNode> tempAppsList = convertJsonNodeToList(apps); applicationsList.addAll(tempAppsList); page++;// ww w .j a v a 2s . co m apps = getApplications(page); } appsNode.put("applications", mapper.valueToTree(applicationsList)); return appsNode; }
From source file:com.infinities.keystone4j.admin.v3.policy.PolicyV3ResourceTest.java
@Test public void testListPolicies() throws JsonProcessingException, IOException { Response response = target("/v3/policies").register(JacksonFeature.class) .register(ObjectMapperResolver.class).request() .header("X-Auth-Token", Config.Instance.getOpt(Config.Type.DEFAULT, "admin_token").asText()).get(); assertEquals(200, response.getStatus()); JsonNode node = JsonUtils.convertToJsonNode(response.readEntity(String.class)); System.err.println(node.toString()); JsonNode policiesJ = node.get("policies"); assertEquals(1, policiesJ.size()); JsonNode policyJ = policiesJ.get(0); assertNotNull(policyJ.get("id").asText()); assertNotNull(policyJ.get("blob").asText()); assertNotNull(policyJ.get("type").asText()); assertNotNull(policyJ.get("user_id").asText()); assertNotNull(policyJ.get("project_id").asText()); assertNotNull(policyJ.get("links")); assertNotNull(policyJ.get("links").get("self").asText()); }
From source file:com.github.fge.jsonschema.core.keyword.syntax.checkers.helpers.SchemaOrSchemaArraySyntaxChecker.java
private void collectPointers(final Collection<JsonPointer> pointers, final SchemaTree tree) { final JsonNode node = getNode(tree); if (node.isObject()) { pointers.add(JsonPointer.of(keyword)); return;// w w w.j a v a 2s . com } for (int index = 0; index < node.size(); index++) pointers.add(JsonPointer.of(keyword, index)); }
From source file:org.lendingclub.mercator.newrelic.NewRelicClientImpl.java
@Override public ObjectNode getAlertPolicies() { ObjectNode alertPoliciesNode = mapper.createObjectNode(); List<JsonNode> alertPoliciesList = new ArrayList<JsonNode>(); int page = 1; JsonNode policies = getAlertPolicies(page); while (policies.size() != 0) { List<JsonNode> tempPoliciesList = convertJsonNodeToList(policies); alertPoliciesList.addAll(tempPoliciesList); page++;/* w w w . j a va 2s . c om*/ policies = getAlertPolicies(page); } alertPoliciesNode.put("policies", mapper.valueToTree(alertPoliciesList)); return alertPoliciesNode; }
From source file:org.envirocar.server.rest.decoding.json.SensorDecoder.java
private Object parseObjectNode(JsonNode value) { Iterator<String> names = value.fieldNames(); Map<String, Object> map = Maps.newHashMapWithExpectedSize(value.size()); while (names.hasNext()) { String name = names.next(); map.put(name, parseNode(value.path(name))); }/*from w w w . j a v a 2 s . com*/ return map; }
From source file:org.envirocar.server.rest.decoding.json.TrackDecoder.java
@Override public Track decode(JsonNode j, MediaType mediaType) { Sensor trackSensor = null;/* w w w. j a v a 2 s. co m*/ Track track = getEntityFactory().createTrack(); if (j.has(GeoJSONConstants.PROPERTIES_KEY)) { JsonNode p = j.path(GeoJSONConstants.PROPERTIES_KEY); if (p.has(JSONConstants.SENSOR_KEY)) { trackSensor = sensorDao.getByIdentifier(p.get(JSONConstants.SENSOR_KEY).asText()); track.setSensor(trackSensor); } track.setName(p.path(JSONConstants.NAME_KEY).textValue()); track.setDescription(p.path(JSONConstants.DESCRIPTION_KEY).textValue()); track.setAppVersion(p.path(JSONConstants.APP_VERSION_KEY).textValue()); track.setObdDevice(p.path(JSONConstants.OBD_DEVICE_KEY).textValue()); track.setTouVersion(p.path(JSONConstants.TOU_VERSION_KEY).textValue()); } if (!j.path(GeoJSONConstants.FEATURES_KEY).isMissingNode()) { JsonNode ms = j.path(GeoJSONConstants.FEATURES_KEY); TrackWithMeasurments twm = new TrackWithMeasurments(track); for (int i = 0; i < ms.size(); i++) { Measurement m = measurementDecoder.decode(ms.get(i), mediaType); m.setTrack(track); if (m.getSensor() == null) { m.setSensor(trackSensor); } twm.addMeasurement(m); } track = twm; } return track; }
From source file:org.activiti.rest.service.api.history.HistoricTaskInstanceIdentityLinkCollectionResourceTest.java
/** * Test querying historic task instance. GET history/historic-task-instances/{taskId}/identitylinks *//*from w w w. jav a2 s.c o m*/ @Deployment public void testGetIdentityLinks() throws Exception { HashMap<String, Object> processVariables = new HashMap<String, Object>(); processVariables.put("stringVar", "Azerty"); processVariables.put("intVar", 67890); processVariables.put("booleanVar", false); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", processVariables); Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); taskService.complete(task.getId()); task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); taskService.setOwner(task.getId(), "test"); String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_HISTORIC_TASK_INSTANCE_IDENTITY_LINKS, task.getId()); // Do the actual call CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), HttpStatus.SC_OK); // Check status and size JsonNode linksArray = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertEquals(2, linksArray.size()); Map<String, JsonNode> linksMap = new HashMap<String, JsonNode>(); for (JsonNode linkNode : linksArray) { linksMap.put(linkNode.get("type").asText(), linkNode); } JsonNode assigneeNode = linksMap.get("assignee"); assertNotNull(assigneeNode); assertEquals("fozzie", assigneeNode.get("userId").asText()); assertTrue(assigneeNode.get("groupId").isNull()); assertEquals(task.getId(), assigneeNode.get("taskId").asText()); assertNotNull(assigneeNode.get("taskUrl").asText()); assertTrue(assigneeNode.get("processInstanceId").isNull()); assertTrue(assigneeNode.get("processInstanceUrl").isNull()); JsonNode ownerNode = linksMap.get("owner"); assertNotNull(ownerNode); assertEquals("test", ownerNode.get("userId").asText()); assertTrue(ownerNode.get("groupId").isNull()); assertEquals(task.getId(), ownerNode.get("taskId").asText()); assertNotNull(ownerNode.get("taskUrl").asText()); assertTrue(ownerNode.get("processInstanceId").isNull()); assertTrue(ownerNode.get("processInstanceUrl").isNull()); }
From source file:com.infinities.keystone4j.admin.v3.service.ServiceResourceTest.java
@Test public void testListServices() throws JsonProcessingException, IOException { final List<Service> services = new ArrayList<Service>(); services.add(service);//from w w w . j ava2 s . com Response response = target("/v3/services").register(JacksonFeature.class) .register(ObjectMapperResolver.class).request() .header("X-Auth-Token", Config.Instance.getOpt(Config.Type.DEFAULT, "admin_token").asText()).get(); assertEquals(200, response.getStatus()); String res = response.readEntity(String.class); JsonNode node = JsonUtils.convertToJsonNode(res); JsonNode servicesJ = node.get("services"); System.err.println(res); assertEquals(1, servicesJ.size()); JsonNode serviceJ = servicesJ.get(0); assertEquals(service.getId(), serviceJ.get("id").asText()); assertEquals(service.getName(), serviceJ.get("name").asText()); assertEquals(service.getDescription(), serviceJ.get("description").asText()); assertEquals(service.getType(), serviceJ.get("type").asText()); }