List of usage examples for com.fasterxml.jackson.databind.node ArrayNode get
public JsonNode get(String paramString)
From source file:io.wcm.caravan.pipeline.impl.JsonPathSelectorTest.java
@Test public void testExtractArrayMultipleStrings() { ArrayNode result = new JsonPathSelector("$.store.book[*].author").call(booksJson); assertEquals(4, result.size());/* www. ja v a 2 s .co m*/ assertEquals("Nigel Rees", result.get(0).asText()); assertEquals("Evelyn Waugh", result.get(1).asText()); }
From source file:org.bonitasoft.web.designer.model.contract.databind.ContractDeserializer.java
private void parseNodeContractInput(ArrayNode inputArray, ContractInputContainer rootNodeInput) throws IOException { for (int i = 0; i < inputArray.size(); i++) { JsonNode childNode = inputArray.get(i); Class<?> inputType = inputType(childNode); if (inputType.equals(NodeContractInput.class)) { NodeContractInput nodeContractInput = newNodeContractInput(childNode); rootNodeInput.addInput(nodeContractInput); parseNodeContractInput(childInput(childNode), nodeContractInput); } else {/* w w w . j a v a2 s. c om*/ rootNodeInput.addInput(newLeafContractInput(childNode, inputType)); } } }
From source file:org.nishkarma.oauth.client.MyGoogle2Client.java
@Override protected MyGoogle2Profile extractUserProfile(final String body) { final MyGoogle2Profile profile = new MyGoogle2Profile(); final JsonNode json = JsonHelper.getFirstNode(body); if (json != null) { profile.setId(JsonHelper.get(json, "id")); profile.addAttribute(MyGoogle2AttributesDefinition.DISPLAY_NAME, JsonHelper.get(json, MyGoogle2AttributesDefinition.DISPLAY_NAME)); ArrayNode emailsArrayNode = (ArrayNode) JsonHelper.get(json, "emails"); if (emailsArrayNode != null) { JsonNode emailsJsonNode = emailsArrayNode.get(0); profile.addAttribute(MyGoogle2AttributesDefinition.EMAIL, JsonHelper.get(emailsJsonNode, "value")); }//from w w w . j ava2s. c om } return profile; }
From source file:com.google.api.server.spi.response.ServletResponseResultWriterTest.java
@Test public void testTypeChangesInArrayAsString() throws Exception { Object[] array = new Object[] { 100L, 200L }; String responseBody = writeToResponse(array); ObjectNode output = ObjectMapperUtil.createStandardObjectMapper().readValue(responseBody, ObjectNode.class); ArrayNode items = (ArrayNode) output.get("items"); assertTrue(items.get(0).isTextual()); assertEquals("100", items.get(0).asText()); assertTrue(items.get(1).isTextual()); assertEquals("200", items.get(1).asText()); }
From source file:org.gitana.platform.client.team.TeamImpl.java
@Override public List<String> getRoleKeys() { List<String> roleKeys = new ArrayList<String>(); ArrayNode array = getArray(FIELD_ROLE_KEYS); for (int i = 0; i < array.size(); i++) { String roleKey = (String) array.get(i).textValue(); roleKeys.add(roleKey);// w w w .j a v a 2s.c o m } return roleKeys; }
From source file:org.springframework.social.vkontakte.api.impl.AbstractVKontakteOperations.java
/** * for responses of VK API 5.0+//from ww w .j a va2s. co m * @param response * @param itemClass * @param <T> * @return */ protected <T> VKArray<T> deserializeVK50ItemsResponse(VKGenericResponse response, Class<T> itemClass) { checkForError(response); JsonNode jsonNode = response.getResponse(); JsonNode itemsNode = jsonNode.get("items"); Assert.isTrue(itemsNode.isArray()); int count = jsonNode.get("count").asInt(); ArrayNode items = (ArrayNode) itemsNode; List<T> elements = new ArrayList<T>(); for (int i = 0; i < items.size(); i++) { elements.add(objectMapper.convertValue(items.get(i), itemClass)); } return new VKArray<T>(count, elements); }
From source file:org.lendingclub.mercator.docker.DockerSerializerModule.java
public ObjectNode flatten(JsonNode n) { ObjectNode out = vanillaObjectMapper.createObjectNode(); Converter<String, String> caseFormat = CaseFormat.UPPER_CAMEL.converterTo(CaseFormat.LOWER_CAMEL); n.fields().forEachRemaining(it -> { JsonNode val = it.getValue(); String key = it.getKey(); key = caseFormat.convert(key);/*from w ww.jav a 2 s . c om*/ if (val.isValueNode()) { out.set(key, it.getValue()); } else if (val.isArray()) { if (val.size() == 0) { out.set(key, val); } boolean valid = true; Class<? extends Object> type = null; ArrayNode an = (ArrayNode) val; for (int i = 0; valid && i < an.size(); i++) { if (!an.get(i).isValueNode()) { valid = false; } if (type != null && an.get(i).getClass() != type) { valid = false; } } } }); renameAttribute(out, "oSType", "osType"); renameAttribute(out, "iD", "id"); renameAttribute(out, "neventsListener", "nEventsListener"); renameAttribute(out, "cPUSet", "cpuSet"); renameAttribute(out, "cPUShares", "cpuShares"); renameAttribute(out, "iPv4Forwarding", "ipv4Forwarding"); renameAttribute(out, "oOMKilled", "oomKilled"); renameAttribute(out, "state_oomkilled", "state_oomKilled"); renameAttribute(out, "bridgeNfIptables", "bridgeNfIpTables"); renameAttribute(out, "bridgeNfIp6tables", "bridgeNfIp6Tables"); out.remove("ngoroutines"); return out; }
From source file:de.jlo.talendcomp.json.JsonComparator.java
/** * Collects the values for the both arrays have in common * @param array1/*from w w w .j a v a 2s . c o m*/ * @param array2 * @return an array which contains all values both arrays have in common */ public ArrayNode intersect(ArrayNode array1, ArrayNode array2) { ArrayNode result = objectMapper.createArrayNode(); for (int i1 = 0, n1 = array1.size(); i1 < n1; i1++) { JsonNode node1 = array1.get(i1); for (int i2 = 0, n2 = array2.size(); i2 < n2; i2++) { JsonNode node2 = array2.get(i2); if (node1.equals(node2)) { result.add(node2); } } } return result; }
From source file:enmasse.queue.scheduler.Artemis.java
@Override public Set<String> getQueueNames() { Set<String> queues = new LinkedHashSet<>(); Message message = createMessage("getQueueNames"); message.setBody(new AmqpValue("[]")); // TODO: Make this method less ugly Message response = doRequest(message); if (response == null) { log.warn("Timed out getting response from broker"); return queues; }/*from w w w . java2s . c o m*/ AmqpValue value = (AmqpValue) response.getBody(); try { ArrayNode root = (ArrayNode) mapper.readTree((String) value.getValue()); ArrayNode elements = (ArrayNode) root.get(0); for (int i = 0; i < elements.size(); i++) { String queueName = elements.get(i).asText(); if (!queueName.equals(replyTo)) { queues.add(queueName); } } } catch (IOException e) { log.error("Error decoding queue names", e); } return queues; }
From source file:org.apache.solr.kelvin.App.java
private void configureTestsFromJsonNode(JsonNode node) throws Exception { if (testCases == null) testCases = new ArrayList<ITestCase>(); //otherwise appends ArrayNode list = ConfigurableLoader.assureArray(node); for (int i = 0; i < list.size(); i++) { JsonNode config = list.get(i); try {//from w ww . j a v a 2 s. c o m ITestCase t = SingletonTestRegistry.instantiate(config); t.configure(config); testCases.add(t); } catch (Exception e) { logger.log(Level.SEVERE, "error reading " + config.toString(), e); } } }