List of usage examples for com.fasterxml.jackson.databind JsonNode size
public int size()
From source file:io.wcm.caravan.pipeline.extensions.hal.action.InlineEmbeddedTest.java
@Test public void shouldStoreInArrayForMultipleResources() { HalResource hal = createHalOutput("multiple"); JsonNode container = hal.getModel().get("multiple"); assertTrue(container.isArray());//w w w .j a v a 2 s.c o m assertEquals(2, container.size()); assertEquals("val2", container.get(0).get("key").asText(null)); }
From source file:edu.berkeley.ground.postgres.dao.core.PostgresStructureVersionDao.java
@Override public StructureVersion retrieveFromDatabase(final long id) throws GroundException { HashMap<String, GroundType> attributes; try {/* ww w. j av a2 s . c om*/ String resultQuery = String.format(SqlConstants.SELECT_STAR_BY_ID, "structure_version", id); JsonNode resultJson = Json.parse(PostgresUtils.executeQueryToJson(dbSource, resultQuery)); if (resultJson.size() == 0) { throw new GroundException(ExceptionType.VERSION_NOT_FOUND, this.getType().getSimpleName(), String.format("%d", id)); } StructureVersion structureVersion = Json.fromJson(resultJson.get(0), StructureVersion.class); String attributeQuery = String.format(SqlConstants.SELECT_STRUCTURE_VERSION_ATTRIBUTES, id); JsonNode attributeJson = Json.parse(PostgresUtils.executeQueryToJson(dbSource, attributeQuery)); attributes = new HashMap<>(); for (JsonNode attribute : attributeJson) { GroundType type = GroundType.fromString(attribute.get("type").asText()); attributes.put(attribute.get("key").asText(), type); } structureVersion = new StructureVersion(structureVersion.getId(), structureVersion.getStructureId(), attributes); return structureVersion; } catch (Exception e) { throw new GroundException(e); } }
From source file:com.github.fge.jsonschema.walk.collectors.helpers.DraftV3TypeKeywordPointerCollector.java
@Override public void collect(final Collection<JsonPointer> pointers, final SchemaTree tree) { final JsonNode node = getNode(tree); /*/*from w w w . ja v a 2 s.c o m*/ * No need to test if the node is an array: if it is not, Iterable * returns an empty iterator. */ final int size = node.size(); for (int index = 0; index < size; index++) if (node.get(index).isObject()) pointers.add(basePointer.append(index)); }
From source file:tests.AutocompleteTests.java
@Test public void shortResultsNoDuplicates() { running(TEST_SERVER, new Runnable() { @Override//from w ww. j av a2s . c om public void run() { final JsonNode jsonObjectIds = Json.parse(call("person?name=Bach&format=ids")); assertThat(jsonObjectIds.isArray()).isTrue(); assertThat(jsonObjectIds.size()).isEqualTo(8); // with id: no dupe final JsonNode jsonObjectShort = Json.parse(call("person?name=Bach&format=short")); assertThat(jsonObjectShort.isArray()).isTrue(); assertThat(jsonObjectShort.size()).isEqualTo(7); // just label: dupe } }); }
From source file:tests.AutocompleteTests.java
public void searchGndOrdering(final String query) { running(TEST_SERVER, new Runnable() { @Override//from w w w . ja v a 2s.co m public void run() { final JsonNode jsonObject = Json.parse(call("person?name=" + query + "&format=short")); assertThat(jsonObject.isArray()).isTrue(); assertThat(jsonObject.size()).isEqualTo(1); assertThat(jsonObject.get(0).asText()).isEqualTo("Mann, Thomas (1875-06-06-1955-08-12)"); } }); }
From source file:com.amazonaws.services.dynamodbv2.replication.manager.models.ReplicationGroupCoordinator.java
public Response getTable(String region, String tableName, String accountId) throws ReplicationGroupCoordinatorException { WebTarget target = client.target(endpoint).path(DESCRIBE_TABLES_API); String json = target.request().get(String.class); logger.finest(json);/* w w w. j a va 2s.c om*/ try { JsonNode tables = new ObjectMapper().readTree(json); if (tables.isArray() && tables.size() == 1) { return Response.ok(tables.get(0)).build(); } else { throw new ReplicationGroupCoordinatorException( "Unnexpected response from the coordinator. It should be an array with one table object in it, but received: " + json); } } catch (IOException e) { throw new ReplicationGroupCoordinatorException( "Failed to parse response from the coordinator: " + json); } }
From source file:com.github.fge.jsonschema.core.keyword.syntax.checkers.hyperschema.LinksSyntaxChecker.java
@Override protected void checkValue(final Collection<JsonPointer> pointers, final MessageBundle bundle, final ProcessingReport report, final SchemaTree tree) throws ProcessingException { final JsonNode node = getNode(tree); final int size = node.size(); JsonNode ldo;/*w ww .j a v a 2 s. com*/ NodeType type; Set<String> set; List<String> list; for (int index = 0; index < size; index++) { ldo = getNode(tree).get(index); type = NodeType.getNodeType(ldo); if (type != NodeType.OBJECT) { report.error(LDOMsg(tree, bundle, "draftv4.ldo.incorrectType", index) .put("expected", NodeType.OBJECT).putArgument("found", type)); continue; } set = Sets.newHashSet(ldo.fieldNames()); list = Lists.newArrayList(REQUIRED_LDO_PROPERTIES); list.removeAll(set); if (!list.isEmpty()) { final ProcessingMessage msg = LDOMsg(tree, bundle, "draftv4.ldo.missingRequired", index); report.error(msg.put("required", REQUIRED_LDO_PROPERTIES).putArgument("missing", list)); continue; } if (ldo.has("schema")) pointers.add(JsonPointer.of(keyword, index, "schema")); if (ldo.has("targetSchema")) pointers.add(JsonPointer.of(keyword, index, "targetSchema")); checkLDO(report, bundle, tree, index); } }
From source file:com.ikanow.aleph2.security.service.IkanowV1CommunityRoleProvider.java
@Override public Tuple2<Set<String>, Set<String>> getRolesAndPermissions(String principalName) { Set<String> roleNames = new HashSet<String>(); Set<String> permissions = new HashSet<String>(); Optional<JsonNode> result; try {/*from w w w . j a v a 2s . com*/ ObjectId objecId = new ObjectId(principalName); result = getPersonStore().getObjectBySpec(CrudUtils.anyOf().when("_id", objecId)).get(); if (result.isPresent()) { JsonNode communities = result.get().get("communities"); if (communities.isArray()) { if (communities.size() > 0) { roleNames.add(principalName + "_communities"); } for (final JsonNode community : communities) { String communityId = community.get("_id").asText(); String communityPermission = PermissionExtractor.createPermission( IkanowV1SecurityService.SECURITY_ASSET_COMMUNITY, Optional.of(ISecurityService.ACTION_WILDCARD), communityId); permissions.add(communityPermission); } } } } catch (Exception e) { logger.error("Caught Exception", e); } return Tuples._2T(roleNames, permissions); }
From source file:org.lendingclub.mercator.newrelic.NewRelicClientImpl.java
@Override public ObjectNode getServers() { ObjectNode serversNode = mapper.createObjectNode(); List<JsonNode> serversList = new ArrayList<JsonNode>(); int page = 1; JsonNode servers = getServers(page); while (servers.size() != 0) { List<JsonNode> tempServersList = convertJsonNodeToList(servers); serversList.addAll(tempServersList); page++;/*from w ww. j a v a 2s . co m*/ servers = getServers(page); } serversNode.put("servers", mapper.valueToTree(serversList)); return serversNode; }
From source file:com.infinities.keystone4j.admin.v3.ednpoint.EndpointResourceTest.java
@Test public void testListEndpoints() throws JsonProcessingException, IOException { final List<Endpoint> endpoints = new ArrayList<Endpoint>(); endpoints.add(endpoint);// ww w .jav a2 s . c om Response response = target("/v3/endpoints").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 ret = response.readEntity(String.class); System.err.println(ret); JsonNode node = JsonUtils.convertToJsonNode(ret); JsonNode endpointsJ = node.get("endpoints"); assertEquals(1, endpointsJ.size()); JsonNode endpointJ = endpointsJ.get(0); assertEquals(endpoint.getId(), endpointJ.get("id").asText()); assertEquals(endpoint.getName(), endpointJ.get("name").asText()); assertEquals(endpoint.getInterfaceType(), endpointJ.get("interface").asText()); assertEquals(endpoint.getServiceid(), endpointJ.get("service_id").asText()); assertEquals(endpoint.getUrl(), endpointJ.get("url").asText()); }