List of usage examples for com.fasterxml.jackson.databind.node ArrayNode size
public int size()
From source file:org.gitana.platform.client.transfer.CopyJob.java
public List<TransferImport> getImports() { List<TransferImport> imports = new ArrayList<TransferImport>(); ArrayNode array = getArray(FIELD_IMPORTS); for (int i = 0; i < array.size(); i++) { ObjectNode object = (ObjectNode) array.get(i); TransferDependencyChain sources = TransferDependencyChain.create((ArrayNode) object.get("sources")); TransferDependencyChain targets = TransferDependencyChain.create((ArrayNode) object.get("targets")); TransferImport transferImport = new TransferImport(sources, targets); imports.add(transferImport);/*ww w . j ava 2 s .c o m*/ } return imports; }
From source file:com.jivesoftware.os.server.http.jetty.jersey.endpoints.killswitch.KillSwitchsRestEndpointsTest.java
@Test public void testListKillSwitches() throws IOException { Mockito.when(killSwitchService.getAll()).thenReturn(new ArrayList<KillSwitch>()); Response result = instance.listKillSwitches(); ArrayNode array = mapper.readValue(result.getEntity().toString(), ArrayNode.class); Assert.assertTrue(array.size() == 0); Mockito.when(killSwitchService.getAll()) .thenReturn(Arrays.asList(new KillSwitch("hi", new AtomicBoolean(true)))); result = instance.listKillSwitches(); array = mapper.readValue(result.getEntity().toString(), ArrayNode.class); Assert.assertTrue(array.size() == 1); }
From source file:com.marklogic.entityservices.tests.TestEntityTypeSPARQL.java
@Test public void sampleSPARQLQueries() throws JsonGenerationException, JsonMappingException, IOException { String docHasTypeHasPropertyHasDatatype = "PREFIX t: <http://marklogic.com/testing-entity-type#> " + "PREFIX es: <http://marklogic.com/entity-services#> " + "ASK where { t:SchemaCompleteEntityType-0.0.1 a es:Model ; " + " es:definitions ?types ." + "?types es:property ?property ." + "?property es:datatype ?datatype " + "}"; assertTrue(queryMgr.executeAsk(queryMgr.newQueryDefinition(docHasTypeHasPropertyHasDatatype))); String assertTypeHasProperties = "PREFIX t: <http://marklogic.com/testing-entity-type/SchemaCompleteEntityType-0.0.1/> " + "PREFIX es: <http://marklogic.com/entity-services#> " + "SELECT ?version where {" + "t:SchemaCompleteEntityType ?version \"0.0.1\" ." + "}"; JacksonHandle handle = queryMgr.executeSelect(queryMgr.newQueryDefinition(assertTypeHasProperties), new JacksonHandle()); JsonNode results = handle.get();// www. java2 s . c o m // to see on System.out // new ObjectMapper().writerWithDefaultPrettyPrinter().writeValue(System.out, results); ArrayNode bindings = (ArrayNode) results.get("results").get("bindings"); assertEquals(1, bindings.size()); assertEquals("http://marklogic.com/entity-services#version", bindings.get(0).get("version").get("value").asText()); }
From source file:com.sqs.tq.fdc.PlainTextReporter.java
@Override public void report(ObjectNode reportData) { out.println();// ww w . j ava2s . c om out.println(String.format("File variants of '%s'", reportData.get("name").textValue())); out.println("---------------------------------------------------"); int idx = 1; for (JsonNode group : (ArrayNode) reportData.get("groups")) { String hash = group.get("hash").textValue(); ArrayNode files = (ArrayNode) group.get("files"); out.println(String.format("%d) #%d times (md5: %s)", idx, files.size(), hash)); for (JsonNode fd : files) { out.println(String.format(" %s", fd.textValue())); } ++idx; } }
From source file:io.cloudslang.content.json.actions.ArraySize.java
/** * This operation determines the number of elements in the given JSON array. If an element * is itself another JSON array, it only counts as 1 element; in other * words, it will not expand and count embedded arrays. Null values are also * considered to be an element./*from w w w. j a v a 2 s. com*/ * * @param array The string representation of a JSON array object. * @return a map containing the output of the operation. Keys present in the map are: * <p/> * <br><br><b>returnResult</b> - This will contain size of the json array given in the input. * <br><b>exception</b> - In case of success response, this result is empty. In case of failure response, * this result contains the java stack trace of the runtime exception. * <br><br><b>returnCode</b> - The returnCode of the operation: 0 for success, -1 for failure. */ @Action(name = "Array Size", outputs = { @Output(OutputNames.RETURN_RESULT), @Output(OutputNames.RETURN_CODE), @Output(OutputNames.EXCEPTION) }, responses = { @Response(text = ResponseNames.SUCCESS, field = OutputNames.RETURN_CODE, value = ReturnCodes.SUCCESS, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.RESOLVED), @Response(text = ResponseNames.FAILURE, field = OutputNames.RETURN_CODE, value = ReturnCodes.FAILURE, matchType = MatchType.COMPARE_EQUAL, responseType = ResponseType.ERROR, isOnFail = true) }) public Map<String, String> execute(@Param(value = Constants.InputNames.ARRAY, required = true) String array) { Map<String, String> returnResult = new HashMap<>(); if (StringUtilities.isBlank(array)) { return populateResult(returnResult, new Exception(NOT_A_VALID_JSON_ARRAY_MESSAGE)); } JsonNode jsonNode; try { ObjectMapper mapper = new ObjectMapper(); jsonNode = mapper.readTree(array); } catch (IOException exception) { final String value = "Invalid jsonObject provided! " + exception.getMessage(); return populateResult(returnResult, value, exception); } final String result; if (jsonNode instanceof ArrayNode) { final ArrayNode asJsonArray = (ArrayNode) jsonNode; result = Integer.toString(asJsonArray.size()); } else { return populateResult(returnResult, new Exception(NOT_A_VALID_JSON_ARRAY_MESSAGE)); } return populateResult(returnResult, result, null); }
From source file:io.wcm.caravan.pipeline.impl.JsonPathSelector.java
@Override public ArrayNode call(JsonNode inputData) throws PathNotFoundException { Stopwatch watch = Stopwatch.createStarted(); ArrayNode arrayNode = JsonPath.using(config).parse(inputData).read(jsonPath, ArrayNode.class); log.debug("selected " + arrayNode.size() + " matches in " + watch.elapsed(MILLISECONDS) + " ms by applying jsonPath " + this.jsonPath); return arrayNode; }
From source file:de.jlo.talendcomp.json.JsonComparator.java
/** * Checks if the array contains the given value * @param array the array which perhaps contains the value * @param value the value to search for//from www . ja v a 2 s . c o m * @return true or false */ public boolean contains(ArrayNode array, JsonNode value) { for (int i = 0, n = array.size(); i < n; i++) { JsonNode node = array.get(i); if (node.equals(value)) { return true; } } return false; }
From source file:com.reprezen.swagedit.schema.ComplexTypeDefinition.java
private void init() { final ArrayNode container = (ArrayNode) content.get(type.getValue()); for (int i = 0; i < container.size(); i++) { JsonNode current = container.get(i); TypeDefinition def = schema.createType(this, type.getValue() + "/" + i, current); if (def != null) { complexTypes.add(def);/*from w ww.j a v a 2 s .c o m*/ } } }
From source file:org.apache.solr.kelvin.responseanalyzers.XmlDoclistExtractorResponseAnalyzerTest.java
public void testResponses() throws Exception { ArrayNode resp = parseResource("/org/apache/solr/kelvin/responseanalyzers/empty.xml"); assertEquals(0, resp.size()); resp = parseResource("/org/apache/solr/kelvin/responseanalyzers/malformedResponse.xml"); assertEquals(0, resp.size());//from www. j a va 2 s . c o m resp = parseResource("/org/apache/solr/kelvin/responseanalyzers/oneResult.xml"); assertEquals(1, resp.size()); resp = parseResource("/org/apache/solr/kelvin/responseanalyzers/multiResult.xml"); assertEquals(10, resp.size()); }
From source file:org.apache.solr.kelvin.responseanalyzers.LegacyResponseAnalyzerTest.java
public void testResponses() throws Exception { ArrayNode resp = parseResource("/org/apache/solr/kelvin/responseanalyzers/legacyOneResult.xml"); assertEquals(1, resp.size()); resp = parseResource("/org/apache/solr/kelvin/responseanalyzers/legacyMultiResult.xml"); assertEquals(10, resp.size());//from www. j a va 2s . c o m }