List of usage examples for com.fasterxml.jackson.databind JsonNode iterator
public final Iterator<JsonNode> iterator()
From source file:com.galenframework.tests.integration.GalenFullJsProjectIT.java
private HashMap<String, TestStatistic> toMap(JsonNode rootNode) { JsonNode testsNode = rootNode.get("tests"); Iterator<JsonNode> it = testsNode.iterator(); HashMap<String, TestStatistic> map = new HashMap<>(); while (it.hasNext()) { JsonNode testNode = it.next();/* ww w . j a va2 s .c o m*/ JsonNode statisticNode = testNode.get("statistic"); map.put(testNode.get("name").asText(), new TestStatistic(statisticNode.get("passed").asInt(), statisticNode.get("errors").asInt(), statisticNode.get("warnings").asInt(), statisticNode.get("total").asInt())); } return map; }
From source file:net.jawr.web.resource.bundle.factory.util.JsonPropertiesSource.java
/** * Converts the json array node to a String * /*from w w w. j a v a 2s . c om*/ * @param jsonArrayNode * the json array node to convert * @return a string corresponding to the json array node */ private String convertToString(JsonNode jsonArrayNode) { StringBuilder strBuilder = new StringBuilder(); Iterator<JsonNode> nodeIterator = jsonArrayNode.iterator(); while (nodeIterator.hasNext()) { JsonNode jsonNode = (JsonNode) nodeIterator.next(); strBuilder.append(jsonNode.asText()); if (nodeIterator.hasNext()) { strBuilder.append(ARRAY_VALUE_SEPARATOR); } } return strBuilder.toString(); }
From source file:com.orasi.sandbox.TestXMLDataProvider.java
@Test(dataProvider = "xmlDataDiningNode") public void testXMLDiningNode(JsonNode node) { JsonNode nlist = node.path("diningList"); Iterator<String> i1 = new IteratorMap<JsonNode, String>(nlist.iterator()) { @Override/*from ww w.j a va 2 s. c om*/ public String apply(JsonNode o) { return o.asText(); } }; List<String> l1 = Lists.newArrayList(i1); List<String> l2 = Lists.newArrayList(DINING_LIST); Assert.assertFalse(Collections.disjoint(l1, l2)); Assert.assertEquals(node.path("diningInfo").path("partySize").asInt(), 1); }
From source file:org.jboss.aerogear.sync.jsonmergepatch.JsonMapperTest.java
@Test public void patchMessageToJson() { final String documentId = "1234"; final String clientId = "client1"; final PatchMessage<JsonMergePatchEdit> patchMessage = patchMessage(documentId, clientId, newJsonMergePatchEdit("Fletch")); 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.get("name").asText(), equalTo("Fletch")); }
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 w w w .jav a 2s .co m*/ while (includesIt.hasNext()) { JsonNode item = includesIt.next(); includes[j] = item.asText(); j++; } return includes; }
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:org.walkmod.conf.providers.yml.RemoveTransformationYMLAction.java
@Override public void doAction(JsonNode node) throws Exception { HashSet<String> transList = new HashSet<String>(transformations); JsonNode transfListNode = null;//from ww w . j a v a2 s . c om if (chain == null || "".equals(chain)) { if (node.has("transformations")) { transfListNode = node.get("transformations"); } } else { if (node.has("chains")) { JsonNode chainsListNode = node.get("chains"); if (chainsListNode.isArray()) { Iterator<JsonNode> it = chainsListNode.iterator(); boolean found = false; while (it.hasNext() && !found) { JsonNode current = it.next(); if (current.has("name")) { String name = current.get("name").asText(); found = name.equals(chain); if (current.has("transformations")) { transfListNode = current.get("transformations"); } } } } } } if (transfListNode != null) { if (transfListNode.isArray()) { ArrayNode transArray = (ArrayNode) transfListNode; Iterator<JsonNode> it = transArray.iterator(); List<Integer> removeIndex = new LinkedList<Integer>(); int i = 0; while (it.hasNext()) { JsonNode transfNode = it.next(); if (transfNode.has("type")) { String type = transfNode.get("type").asText(); if (transList.contains(type)) { removeIndex.add(i); } } i++; } for (Integer pos : removeIndex) { transArray.remove(pos); } } provider.write(node); } }
From source file:architecture.ee.web.community.social.facebook.FacebookServiceProvider.java
public java.util.List<Post> getHomeFeed(int offset, int limit) { Token accessToken = getAccessToken(getAccessToken(), ""); OAuthRequest request = new OAuthRequest(Verb.GET, GRAPH_API_URL + "me/home"); request.addBodyParameter("offset", String.valueOf(offset)); request.addBodyParameter("limit", String.valueOf(limit)); getOAuthService().signRequest(accessToken, request); Response response = request.send(); List<Post> posts;/*from w ww. j ava2s .c om*/ try { ObjectMapper mapper = getObjectMapper(); JsonNode dataNode = mapper.readTree(response.getBody()); JsonNode dataNode2 = dataNode.get("data"); posts = new ArrayList<Post>(); for (Iterator<JsonNode> iterator = dataNode2.iterator(); iterator.hasNext();) { JsonNode node = iterator.next(); posts.add(deserializePost(mapper, null, Post.class, (ObjectNode) node)); } } catch (Exception e) { return Collections.EMPTY_LIST; } return posts; }
From source file:io.fabric8.kubernetes.api.KubernetesHelper.java
protected static void addObjectsToItemArray(ArrayNode itemArray, Object object) throws IOException { JsonNode node = toJsonNode(object);//from w w w . j a v a 2 s .c o m JsonNode items = node.get("items"); if (items != null && items.isArray()) { Iterator<JsonNode> iter = items.iterator(); for (JsonNode item : items) { itemArray.add(item); } } else { itemArray.add(node); } }
From source file:org.keycloak.authz.server.services.common.KeycloakIdentity.java
@Override public Attributes getAttributes() { HashMap<String, Collection<String>> attributes = new HashMap<>(); try {/*w w w .j ava 2 s.com*/ ObjectNode objectNode = JsonSerialization.createObjectNode(this.accessToken); Iterator<String> iterator = objectNode.fieldNames(); List<String> roleNames = new ArrayList<>(); while (iterator.hasNext()) { String fieldName = iterator.next(); JsonNode fieldValue = objectNode.get(fieldName); List<String> values = new ArrayList<>(); values.add(fieldValue.asText()); if (fieldName.equals("realm_access")) { JsonNode grantedRoles = fieldValue.get("roles"); if (grantedRoles != null) { Iterator<JsonNode> rolesIt = grantedRoles.iterator(); while (rolesIt.hasNext()) { roleNames.add(rolesIt.next().asText()); } } } if (fieldName.equals("resource_access")) { Iterator<JsonNode> resourceAccessIt = fieldValue.iterator(); while (resourceAccessIt.hasNext()) { JsonNode grantedRoles = resourceAccessIt.next().get("roles"); if (grantedRoles != null) { Iterator<JsonNode> rolesIt = grantedRoles.iterator(); while (rolesIt.hasNext()) { roleNames.add(rolesIt.next().asText()); } } } } attributes.put(fieldName, values); } attributes.put("roles", roleNames); } catch (Exception e) { throw new RuntimeException("Error while reading attributes from security token.", e); } return Attributes.from(attributes); }