List of usage examples for com.fasterxml.jackson.databind JsonNode iterator
public final Iterator<JsonNode> iterator()
From source file:org.walkmod.conf.providers.yml.AddModulesYMLAction.java
@Override public void doAction(JsonNode node) throws Exception { ArrayNode aux = null;/* w w w . j a v a2s . c o m*/ HashSet<String> modulesToAdd = new HashSet<String>(modules); if (node.has("modules")) { JsonNode list = node.get("modules"); Iterator<JsonNode> it = list.iterator(); while (it.hasNext()) { JsonNode next = it.next(); modulesToAdd.remove(next.asText().trim()); } if (!modulesToAdd.isEmpty()) { if (list.isArray()) { aux = (ArrayNode) list; } } } else { aux = new ArrayNode(provider.getObjectMapper().getNodeFactory()); } if (!modulesToAdd.isEmpty()) { for (String moduleToAdd : modulesToAdd) { TextNode prov = new TextNode(moduleToAdd); aux.add(prov); } ObjectNode auxNode = (ObjectNode) node; auxNode.set("modules", aux); provider.write(node); } }
From source file:org.walkmod.conf.providers.yml.AddProviderConfigYMLAction.java
@Override public void doAction(JsonNode node) throws Exception { ObjectMapper mapper = provider.getObjectMapper(); if (node.has("conf-providers")) { JsonNode list = node.get("conf-providers"); Iterator<JsonNode> it = list.iterator(); boolean found = false; while (it.hasNext() && !found) { JsonNode next = it.next();/*from ww w .j a v a2s.c om*/ found = providerCfg.getType().equals(next.get("type").asText()); } if (!found) { if (list.isArray()) { ArrayNode aux = (ArrayNode) list; ObjectNode prov = new ObjectNode(mapper.getNodeFactory()); prov.set("type", new TextNode(providerCfg.getType())); Map<String, Object> params = providerCfg.getParameters(); if (params != null && !params.isEmpty()) { populateParams(prov, params); } aux.add(prov); provider.write(node); return; } } } else { ArrayNode aux = new ArrayNode(mapper.getNodeFactory()); ObjectNode prov = new ObjectNode(mapper.getNodeFactory()); prov.set("type", new TextNode(providerCfg.getType())); Map<String, Object> params = providerCfg.getParameters(); if (params != null && !params.isEmpty()) { populateParams(prov, params); } aux.add(prov); ObjectNode auxNode = (ObjectNode) node; auxNode.set("conf-providers", aux); provider.write(node); return; } return; }
From source file:org.keycloak.adapters.elytron.KeycloakRoleDecoder.java
@Override public Set<String> decodeRoles(Attributes attributes) { Attributes.Entry realmAccess = attributes.get("realm_access"); if (realmAccess != null) { String realmAccessValue = realmAccess.get(0); try {/*from w w w . j ava 2 s . co m*/ JsonNode jsonNode = new ObjectMapper().readTree(realmAccessValue); JsonNode roles = jsonNode.get("roles"); Set<String> roleSet = new HashSet<>(); Iterator<JsonNode> iterator = roles.iterator(); while (iterator.hasNext()) { roleSet.add(iterator.next().asText()); } return roleSet; } catch (IOException e) { e.printStackTrace(); } } return Collections.emptySet(); }
From source file:com.orasi.sandbox.TestJSONDataProvider.java
@Test(dataProvider = "dataArrayNode") public void testArrayNode(JsonNode a) { Iterator<Integer> it = new IteratorMap<JsonNode, Integer>(a.iterator()) { @Override/*ww w .j a v a 2s .co m*/ public Integer apply(JsonNode i) { return i.asInt(); } }; if (it.next().equals(1)) { Assert.assertEquals(it, new ArrayIterator(new Integer[] { 2, 3, 4, 5 })); } else { Assert.assertEquals(it, new ArrayIterator(new Integer[] { 4, 3, 2, 1 })); } }
From source file:com.orasi.sandbox.TestYAMLDataProvider.java
@Test(dataProvider = "dataArrayNodeYAML") public void testArrayNodeYAML(JsonNode a) { Iterator<Integer> it = new IteratorMap<JsonNode, Integer>(a.iterator()) { @Override/* w w w. j ava 2 s .c om*/ public Integer apply(JsonNode i) { return i.asInt(); } }; if (it.next().equals(1)) { Assert.assertEquals(it, new ArrayIterator(new Integer[] { 2, 3, 4, 5 })); } else { Assert.assertEquals(it, new ArrayIterator(new Integer[] { 4, 3, 2, 1 })); } }
From source file:com.orasi.sandbox.TestXMLDataProvider.java
@Test(dataProvider = "xmlDataArrayNode") public void testXMLArrayNode(JsonNode a) { Iterator<Integer> it = new IteratorMap<JsonNode, Integer>(a.iterator()) { @Override//from w w w .ja v a2 s. co m public Integer apply(JsonNode i) { return i.asInt(); } }; if (it.next().equals(1)) { Assert.assertEquals(it, new ArrayIterator(new Integer[] { 2, 3, 4, 5 })); } else { Assert.assertEquals(it, new ArrayIterator(new Integer[] { 4, 3, 2, 1 })); } }
From source file:org.wikidata.couchbase.MongoPersistHandler.java
private JsonNode transformNode(JsonNode node) { Map.Entry<String, JsonNode> entry = node.iterator().next().fields().next(); JsonNode transformedNode = entry.getValue(); return transformedNode; }
From source file:com.galenframework.tests.integration.GalenFullJsProjectIT.java
private List<String> collectAllErrorMessages(JsonNode rootNode, String jsonReportPath) throws IOException { JsonNode testsNode = rootNode.get("tests"); Iterator<JsonNode> it = testsNode.iterator(); List<String> errorMessages = new LinkedList<>(); while (it.hasNext()) { String testId = it.next().get("testId").asText(); errorMessages.addAll(collectAllErrorMessagesFromIndividualTestReport(testId, jsonReportPath)); }/*from w w w .j a v a 2 s . c o m*/ return errorMessages; }
From source file:com.orasi.sandbox.TestJSONDataProvider.java
@Test(dataProvider = "dataDiningNode") public void testDiningNode(JsonNode node) { JsonNode nlist = node.path("diningList"); Iterator<String> i1 = new IteratorMap<JsonNode, String>(nlist.iterator()) { @Override/* w w w. jav a 2 s . com*/ public String apply(JsonNode o) { return o.asText(); } }; Iterator<String> i2 = new ArrayIterator(DINING_LIST); Assert.assertEquals(i1, i2); Assert.assertEquals(node.path("diningInfo").path("partySize").asInt(), 1); }
From source file:com.orasi.sandbox.TestYAMLDataProvider.java
@Test(dataProvider = "dataDiningNodeYAML") public void testDiningNodeYAML(JsonNode node) { JsonNode nlist = node.path("diningList"); Iterator<String> i1 = new IteratorMap<JsonNode, String>(nlist.iterator()) { @Override/*from w ww . ja va 2 s. c om*/ public String apply(JsonNode o) { return o.asText(); } }; Iterator<String> i2 = new ArrayIterator(DINING_LIST); Assert.assertEquals(i1, i2); Assert.assertEquals(node.path("diningInfo").path("partySize").asInt(), 1); }