List of usage examples for com.fasterxml.jackson.databind JsonNode size
public int size()
From source file:com.jive.myco.seyren.core.service.checker.GraphiteTargetChecker.java
/** * Loop through the datapoints in reverse order until we find the latest non-null value *//*from w w w. j a v a2 s .c om*/ private BigDecimal getLatestValue(JsonNode node) throws Exception { JsonNode datapoints = node.get("datapoints"); for (int i = datapoints.size() - 1; i >= 0; i--) { String value = datapoints.get(i).get(0).asText(); if (!value.equals("null")) { return new BigDecimal(value); } } LOGGER.warn("{}", node); throw new InvalidGraphiteValueException( "Could not find a valid datapoint for target: " + node.get("target")); }
From source file:org.springframework.tuple.JsonNodeToTupleConverter.java
private List<Object> nodeToList(JsonNode node) { List<Object> list = new ArrayList<Object>(node.size()); for (int i = 0; i < node.size(); i++) { JsonNode item = node.get(i);/*from w w w .j ava 2 s . c om*/ if (item.isObject()) { list.add(convert(item)); } else if (item.isArray()) { list.add(nodeToList(item)); } else if (item.isNull()) { list.add(null); } else if (item.isBoolean()) { list.add(item.booleanValue()); } else if (item.isNumber()) { list.add(item.numberValue()); } else { list.add(item.asText()); } } return list; }
From source file:com.github.fge.jsonschema.syntax.checkers.draftv4.RequiredSyntaxChecker.java
@Override protected void checkValue(final Collection<JsonPointer> pointers, final ProcessingReport report, final SchemaTree tree) throws ProcessingException { final JsonNode node = getNode(tree); final int size = node.size(); if (size == 0) { report.error(newMsg(tree, "emptyArray")); return;/*from w ww .j a v a2s .c o m*/ } final Set<Equivalence.Wrapper<JsonNode>> set = Sets.newHashSet(); boolean uniqueElements = true; JsonNode element; NodeType type; for (int index = 0; index < size; index++) { element = node.get(index); uniqueElements = set.add(EQUIVALENCE.wrap(element)); type = NodeType.getNodeType(element); if (type != NodeType.STRING) report.error(newMsg(tree, "incorrectElementType").put("index", index) .put("expected", EnumSet.of(NodeType.STRING)).put("found", type)); } if (!uniqueElements) report.error(newMsg(tree, "elementsNotUnique")); }
From source file:com.github.fge.jsonschema.core.keyword.syntax.checkers.draftv4.RequiredSyntaxChecker.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(); if (size == 0) { report.error(newMsg(tree, bundle, "common.array.empty")); return;//from w w w. j a va 2 s .co m } final Set<Equivalence.Wrapper<JsonNode>> set = Sets.newHashSet(); boolean uniqueElements = true; JsonNode element; NodeType type; for (int index = 0; index < size; index++) { element = node.get(index); uniqueElements = set.add(EQUIVALENCE.wrap(element)); type = NodeType.getNodeType(element); if (type != NodeType.STRING) report.error(newMsg(tree, bundle, "common.array.element.incorrectType").putArgument("index", index) .putArgument("expected", EnumSet.of(NodeType.STRING)).putArgument("found", type)); } if (!uniqueElements) report.error(newMsg(tree, bundle, "common.array.duplicateElements")); }
From source file:com.infinities.keystone4j.admin.v2.ApiV2ResourceTest.java
@Test public void testGetVersions() throws JsonParseException, IOException { Response response = target("/").path("v2.0").request().get(); assertEquals(200, response.getStatus()); JsonNode node = JsonUtils.convertToJsonNode(response.readEntity(String.class)); JsonNode versionV2 = node.get("version"); assertNotNull(versionV2);/* w w w . j av a 2s . c o m*/ assertEquals("v2.0", versionV2.get("id").asText()); assertEquals("stable", versionV2.get("status").asText()); assertEquals("2014-04-17T00:00:00Z", versionV2.get("updated").asText()); JsonNode linksV2 = versionV2.get("links"); assertEquals(3, linksV2.size()); JsonNode linkV2_0 = linksV2.get(0); assertEquals("self", linkV2_0.get("rel").asText()); String url = Config.Instance.getOpt(Config.Type.DEFAULT, "admin_endpoint").asText(); url = Config.replaceVarWithConf(url) + "v2.0/"; assertEquals(url, linkV2_0.get("href").asText()); JsonNode linkV2_1 = linksV2.get(1); assertEquals("describeby", linkV2_1.get("rel").asText()); assertEquals("text/html", linkV2_1.get("type").asText()); assertEquals("http://docs.openstack.org/api/openstack-identity-service/v2.0/content/", linkV2_1.get("href").asText()); JsonNode linkV2_2 = linksV2.get(2); assertEquals("describeby", linkV2_2.get("rel").asText()); assertEquals("application/pdf", linkV2_2.get("type").asText()); assertEquals("http://docs.openstack.org/api/openstack-identity-service/2.0/identity-dev-guide-2.0.pdf", linkV2_2.get("href").asText()); JsonNode mediasV2 = versionV2.get("media-types"); assertEquals(1, mediasV2.size()); JsonNode mediaV2 = mediasV2.get(0); assertEquals("application/json", mediaV2.get("base").asText()); assertEquals("application/vnd.openstack.identity-v2.0+json", mediaV2.get("type").asText()); }
From source file:com.github.fge.jsonschema.keyword.validator.draftv4.AllOfValidator.java
@Override public void validate(final Processor<FullData, FullData> processor, final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final SchemaTree tree = data.getSchema(); final JsonPointer schemaPointer = tree.getPointer(); final JsonNode schemas = tree.getNode().get(keyword); final int size = schemas.size(); final ObjectNode fullReport = FACTORY.objectNode(); int nrSuccess = 0; ListProcessingReport subReport;//from ww w. j a v a 2s.co m JsonPointer ptr; FullData newData; for (int index = 0; index < size; index++) { subReport = new ListProcessingReport(report.getLogLevel(), LogLevel.FATAL); ptr = schemaPointer.append(JsonPointer.of(keyword, index)); newData = data.withSchema(tree.setPointer(ptr)); processor.process(subReport, newData); fullReport.put(ptr.toString(), subReport.asJson()); if (subReport.isSuccess()) nrSuccess++; } if (nrSuccess != size) report.error(newMsg(data, bundle, "err.draftv4.allOf.fail").putArgument("matched", nrSuccess) .putArgument("nrSchemas", size).put("reports", fullReport)); }
From source file:com.github.fge.jsonschema.keyword.validator.draftv4.AnyOfValidator.java
@Override public void validate(final Processor<FullData, FullData> processor, final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final SchemaTree tree = data.getSchema(); final JsonPointer schemaPointer = tree.getPointer(); final JsonNode schemas = tree.getNode().get(keyword); final int size = schemas.size(); final ObjectNode fullReport = FACTORY.objectNode(); int nrSuccess = 0; ListProcessingReport subReport;// ww w . j a v a 2 s. c om JsonPointer ptr; FullData newData; for (int index = 0; index < size; index++) { subReport = new ListProcessingReport(report.getLogLevel(), LogLevel.FATAL); ptr = schemaPointer.append(JsonPointer.of(keyword, index)); newData = data.withSchema(tree.setPointer(ptr)); processor.process(subReport, newData); fullReport.put(ptr.toString(), subReport.asJson()); if (subReport.isSuccess()) nrSuccess++; } if (nrSuccess == 0) report.error(newMsg(data, bundle, "err.common.schema.noMatch").putArgument("nrSchemas", size) .put("reports", fullReport)); }
From source file:com.github.fge.jsonschema.keyword.validator.draftv4.OneOfValidator.java
@Override public void validate(final Processor<FullData, FullData> processor, final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final SchemaTree tree = data.getSchema(); final JsonPointer schemaPointer = tree.getPointer(); final JsonNode schemas = tree.getNode().get(keyword); final int size = schemas.size(); final ObjectNode fullReport = FACTORY.objectNode(); int nrSuccess = 0; ListProcessingReport subReport;//from w ww . j a va 2 s.c o m JsonPointer ptr; FullData newData; for (int index = 0; index < size; index++) { subReport = new ListProcessingReport(report.getLogLevel(), LogLevel.FATAL); ptr = schemaPointer.append(JsonPointer.of(keyword, index)); newData = data.withSchema(tree.setPointer(ptr)); processor.process(subReport, newData); fullReport.put(ptr.toString(), subReport.asJson()); if (subReport.isSuccess()) nrSuccess++; } if (nrSuccess != 1) report.error(newMsg(data, bundle, "err.draftv4.oneOf.fail").putArgument("matched", nrSuccess) .putArgument("nrSchemas", size).put("reports", fullReport)); }
From source file:tests.SearchTests.java
private static void searchName(final String name, final int results) { running(TEST_SERVER, new Runnable() { @Override/* www . j a v a 2 s . c o m*/ public void run() { final JsonNode jsonObject = Json .parse(call("person?name=" + name.replace(" ", "%20") + "&format=short")); assertThat(jsonObject.isArray()).isTrue(); assertThat(jsonObject.size()).isEqualTo(results); if (results > 0) { assertThat(Iterables.any(list(jsonObject), new Predicate<String>() { @Override public boolean apply(String s) { return s.equals("Schmidt, Hannelore (1919-03-03-2010-10-21)"); } })).isTrue(); } } }); }
From source file:io.sqp.client.InformationRequestTest.java
@Test(groups = { "native-transbase-only" }) public void RequestTransbaseRangedDateTimeSchema() throws IOException { String schema = connection.getTypeSchema("tb_datetime[mo:hh]").join(); JsonNode schemaNode = new ObjectMapper().readTree(schema); assertThat(schemaNode.get("minItems").asInt(), is(3)); assertThat(schemaNode.get("additionalItems").asBoolean(), is(false)); JsonNode itemsNode = schemaNode.get("items"); assertThat(itemsNode.size(), is(3)); checkDateFieldSchema(itemsNode.get(0), "MO", 1, 12, "Months"); checkDateFieldSchema(itemsNode.get(1), "DD", 1, 31, "Days"); checkDateFieldSchema(itemsNode.get(2), "HH", 0, 23, "Hours"); }