List of usage examples for com.fasterxml.jackson.databind JsonNode size
public int size()
From source file:edu.berkeley.ground.postgres.dao.version.PostgresVersionSuccessorDao.java
/** * Retrieve a version successor from the database. * * @param dbId the id of the successor to retrieve * @return the retrieved version successor * @throws GroundException either the successor didn't exist or couldn't be retrieved *//*from ww w . j a v a 2s .c o m*/ @Override public VersionSuccessor retrieveFromDatabase(long dbId) throws GroundException { try { String sql = String.format(SqlConstants.SELECT_VERSION_SUCCESSOR, dbId); JsonNode json = Json.parse(PostgresUtils.executeQueryToJson(dbSource, sql)); if (json.size() == 0) { throw new GroundException(ExceptionType.OTHER, String.format("Version Successor with id %d does not exist.", dbId)); } json = json.get(0); return new VersionSuccessor(dbId, json.get("fromVersionId").asLong(), json.get("toVersionId").asLong()); } catch (Exception e) { throw new GroundException(e); } }
From source file:io.wcm.caravan.pipeline.extensions.hal.action.InlineEmbeddedCollectionTest.java
@Test public void shouldStoreEmbeddedCollectionInArray() { HalResource hal = createHalOutput("embedded"); JsonNode container = hal.getModel().get("embedded"); assertTrue(container.isArray());//from w ww. j av a2s. c o m assertEquals(2, container.size()); assertEquals("val1", container.get(0).get("key").asText(null)); }
From source file:tests.SearchResourceNarrowBySetTests.java
private void searchUrlStyle(final String set) { running(TEST_SERVER, new Runnable() { @Override// w w w .j a v a 2 s . c om public void run() { String response = call("resource?author=Hundt&set=" + set); assertThat(response).isNotNull(); final JsonNode jsonObjectIds = Json.parse(response); assertThat(jsonObjectIds.isArray()).isTrue(); assertThat(jsonObjectIds.size()).isEqualTo(1 + META); assertThat(jsonObjectIds.get(0 + META).toString()).contains(SET_FULL); } }); }
From source file:com.hortonworks.pso.data.generator.fields.NestedField.java
public NestedField(JsonNode node) { super(node);//from w w w. j av a 2 s. c o m delimiter = node.get("delimiter").asText(); if (node.has("repeats")) { repeats = node.get("repeats").asInt(); repeatsDelimiter = node.get("repeatsDelimiter").asText(); } JsonNode fieldsNode = node.get("fields"); for (int i = 0; i < fieldsNode.size(); i++) { JsonNode fieldNode = fieldsNode.get(i); if (fieldNode.has("string")) { FieldType field = new StringField(fieldNode.get("string")); addFields(field); } else if (fieldNode.has("number")) { FieldType field = new NumberField(fieldNode.get("number")); addFields(field); } else if (fieldNode.has("ip")) { FieldType field = new IPAddressField(fieldNode.get("ip")); addFields(field); } else if (fieldNode.has("boolean")) { FieldType field = new BooleanField(fieldNode.get("boolean")); addFields(field); } else if (fieldNode.has("date")) { FieldType field = new DateField(fieldNode.get("date")); addFields(field); } else if (fieldNode.has("null")) { FieldType field = new NullField(fieldNode.get("null")); addFields(field); } else if (fieldNode.has("start.stop")) { StartStopFields fields = new StartStopFields(fieldNode.get("start.stop")); addFields(fields.getStartField()); addFields(fields.getStopField()); } else if (fieldNode.has("nested")) { FieldType field = new NestedField(fieldNode.get("nested")); addFields(field); } } }
From source file:com.hortonworks.pso.data.generator.fields.StringField.java
public StringField(JsonNode node) { super(node);//w ww. j a v a2s . co m if (node.has("random")) { JsonNode rNode = node.get("random"); if (rNode.get("min") != null) min = rNode.get("min").asInt(); if (rNode.get("max") != null) max = rNode.get("max").asInt(); if (min < max) diff = Math.abs(max - min); if (rNode.get("chars") != null) { charStr = rNode.get("chars").asText(); } if (rNode.get("pool") != null) { // size is required poolSize = rNode.get("pool").get("size").asInt(); fillPool(); } } else if (node.has("set")) { JsonNode setNode = node.get("set"); type = TYPE.SET; set = new String[setNode.size()]; int i = 0; for (Iterator<JsonNode> it = setNode.elements(); it.hasNext();) { JsonNode element = it.next(); set[i++] = element.asText(); } } }
From source file:org.walkmod.conf.entities.JSONConfigParser.java
public String[] getFileSet(JsonNode parent) { String[] includes = new String[parent.size()]; Iterator<JsonNode> includesIt = parent.iterator(); int j = 0;//from ww w .j a va2 s.c o m while (includesIt.hasNext()) { JsonNode item = includesIt.next(); includes[j] = item.asText(); j++; } return includes; }
From source file:com.basistech.dm.osgitest.BundleIT.java
@Test public void jsonWorksABit() throws Exception { List<Name> names = Lists.newArrayList(); Name.Builder builder = new Name.Builder("Fred"); names.add(builder.build());/*w w w.j a va 2s . com*/ builder = new Name.Builder("George"); builder.languageOfOrigin(LanguageCode.ENGLISH).script(ISO15924.Latn).languageOfUse(LanguageCode.FRENCH); names.add(builder.build()); ObjectMapper mapper = objectMapper(); String json = mapper.writeValueAsString(names); // one way to inspect the works is to read it back in _without_ our customized mapper. ObjectMapper plainMapper = new ObjectMapper(); JsonNode tree = plainMapper.readTree(json); Assert.assertTrue(tree.isArray()); Assert.assertEquals(2, tree.size()); JsonNode node = tree.get(0); Assert.assertTrue(node.has("text")); Assert.assertEquals("Fred", node.get("text").asText()); Assert.assertFalse(node.has("script")); Assert.assertFalse(node.has("languageOfOrigin")); Assert.assertFalse(node.has("languageOfUse")); List<Name> readBack = mapper.readValue(json, new TypeReference<List<Name>>() { }); Assert.assertEquals(names, readBack); }
From source file:org.jboss.aerogear.sync.jsonpatch.JsonMapperTest.java
@Test public void patchMessageToJson() { final String documentId = "1234"; final String clientId = "client1"; final PatchMessage<JsonPatchEdit> patchMessage = patchMessage(documentId, clientId, newJsonPatchEdit()); final String json = JsonMapper.toJson(patchMessage); final JsonNode jsonNode = JsonMapper.asJsonNode(json); assertThat(jsonNode.get("msgType").asText(), equalTo("patch")); assertThat(jsonNode.get("id").asText(), equalTo(documentId)); assertThat(jsonNode.get("clientId").asText(), equalTo(clientId)); final JsonNode editsNode = jsonNode.get("edits"); assertThat(editsNode.isArray(), is(true)); assertThat(editsNode.size(), is(1)); final JsonNode edit = editsNode.iterator().next(); assertThat(edit.get("serverVersion").asText(), equalTo("0")); assertThat(edit.get("clientVersion").asText(), equalTo("0")); final JsonNode diffs = edit.get("diffs"); assertThat(diffs.isArray(), is(true)); final JsonNode patch = diffs.get(0); assertThat(patch.get("op").asText(), equalTo("replace")); assertThat(patch.get("path").asText(), equalTo("/name")); assertThat(patch.get("value").asText(), equalTo("Fletch")); }
From source file:io.sqp.schemamatcher.fieldmatchers.ItemsSchemaArrayMatcher.java
public boolean isCompatibleToSchemaArray(JsonNode schemaArray, AdditionalItemsField otherAdditional) { int numItems = _schemaMatchers.length; int otherNumItems = schemaArray.size(); for (int i = 0; i < Math.min(numItems, otherNumItems); i++) { if (!_schemaMatchers[i].isCompatibleTo(schemaArray.get(i))) { return false; }/*from ww w .ja v a 2 s.c o m*/ } if (otherNumItems >= numItems) { return checkAdditionalItemsAreCompatible(schemaArray, otherAdditional); } else { return checkRemainingItemsAreCompatible(otherAdditional, otherNumItems); } }
From source file:com.hortonworks.pso.data.generator.StringFieldTest.java
@Test public void TestOne() { assertTrue(true);//from w w w .ja v a 2 s .c om ObjectMapper mapper = new ObjectMapper(); try { JsonNode rootNode = mapper.readValue(new File("src/main/resources/sample-record-generator.json"), JsonNode.class); System.out.println(rootNode.size()); JsonNode array = rootNode.get("fields"); System.out.println(array.size()); JsonNode field1 = array.get(0); System.out.println(field1.size()); JsonNode f1type = field1.get("string"); StringField sf = new StringField(f1type); System.out.println(sf.getValue()); } catch (Exception e) { e.printStackTrace(); } }