List of usage examples for com.fasterxml.jackson.databind JsonNode forEach
default void forEach(Consumer<? super T> action)
From source file:com.ibm.watson.catalyst.jumpqa.trec.TrecReader.java
private static List<String> getParagraphs(final JsonNode trecJson) { final JsonNode paragraphs = trecJson.get("paragraphs"); final List<String> result = new ArrayList<String>(); paragraphs.forEach((par) -> result.add(par.asText())); return result; }
From source file:com.linecorp.armeria.server.grpc.GrpcDocServiceTest.java
private static void removeDocStrings(JsonNode json) { if (json.isObject()) { ((ObjectNode) json).remove("docString"); }//from ww w. ja v a 2 s .c o m if (json.isObject() || json.isArray()) { json.forEach(GrpcDocServiceTest::removeDocStrings); } }
From source file:net.bcsw.sdnwlan.config.AccessPointConfig.java
public static AccessPointConfig valueOf(JsonNode accessNode) throws ConfigException { try {//from w ww. j a va2 s . co m // First some required values MacAddress macAddress = MacAddress.valueOf(accessNode.path(MAC_ADDRESS).asText()); if (macAddress == null || macAddress.equals(MacAddress.ZERO)) { // TODO: Could stand a few more checks here... throw new IllegalArgumentException("Invalid MAC Address"); } List<ConnectPoint> connections = Lists.newArrayList(); JsonNode gateways = accessNode.get(CONNECTIONS); if (gateways != null) { gateways.forEach(jsonNode -> connections.add(ConnectPoint.deviceConnectPoint(jsonNode.asText()))); } if (connections.size() == 0) { throw new IllegalArgumentException("Invalid/missing access point connnection"); } List<GatewayConfig> defaultGateways = Lists.newArrayList(); if (accessNode.has(GatewayConfig.GATEWAY_CONFIG)) { ArrayNode gwConfigArray = (ArrayNode) accessNode.get(GatewayConfig.GATEWAY_CONFIG); gwConfigArray.forEach(gwNode -> { try { defaultGateways.add(GatewayConfig.valueOf(gwNode)); } catch (ConfigException e) { throw new IllegalArgumentException("Error parsing gateway configs", e); } }); } if (defaultGateways.size() == 0) { throw new IllegalArgumentException("Invalid/missing default gateways"); } /////////////////////////////////////////////////////////////////////// // Now other minor or optional values // TODO: Some additional error checking would be good idea here String name = accessNode.path(NAME).asText("").trim(); double longitude = accessNode.path(LONGITUDE).asDouble(0.0); double latitude = accessNode.path(LATITUDE).asDouble(0.0); double altitude = accessNode.path(ALTITUDE).asDouble(0.0); Map<IpGatewayAndMask, List<VlanId>> otherGateways = Maps.newHashMap(); if (accessNode.has(OTHER_VIDS)) { ArrayNode vidNodeArray = (ArrayNode) accessNode.path(OTHER_VIDS); try { vidNodeArray.forEach(vidNode -> { String dummy = "OtherVid entry: " + vidNode.toString(); IpGatewayAndMask gateway = IpGatewayAndMask .valueOf(vidNode.get(OTHER_VIDS_GATEWAY).asText()); List<VlanId> otherVlans = Lists.newArrayList(); JsonNode otherVids = vidNode.get(OTHER_VIDS_VLANS); if (otherVids != null) { otherVids.forEach(jsonNode -> otherVlans.add(VlanId.vlanId((short) jsonNode.asInt()))); } if (otherGateways.put(gateway, otherVlans) != null) { throw new IllegalArgumentException( "Duplicate gateway in othervid list: " + gateway.toString()); } }); } catch (IllegalArgumentException e) { throw new ConfigException("Error parsing compute node connections", e); } } IngressVlans ingressVlans = new IngressVlans(); if (accessNode.has(IngressVlans.INGRESS_VLANS)) { ingressVlans = new IngressVlans((ArrayNode) accessNode.path(IngressVlans.INGRESS_VLANS)); } return new AccessPointConfig(name, macAddress, ingressVlans, defaultGateways, longitude, latitude, altitude, otherGateways, connections); } catch (IllegalArgumentException e) { throw new ConfigException("Error parsing compute node connections", e); } }
From source file:com.nirmata.workflow.details.JsonSerializer.java
public static RunnableTaskDag getRunnableTaskDag(JsonNode node) { List<TaskId> children = Lists.newArrayList(); JsonNode childrenNode = node.get("dependencies"); if ((childrenNode != null) && (childrenNode.size() > 0)) { childrenNode.forEach(n -> children.add(new TaskId(n.asText()))); }/* w w w.ja v a2s .co m*/ return new RunnableTaskDag(new TaskId(node.get("taskId").asText()), children); }
From source file:com.baasbox.service.scripting.ScriptingService.java
private static void append(List<String> list, JsonNode node) { if (node == null || node.isNull() || node.isMissingNode() || node.isObject()) return;/*w w w. j av a 2 s.com*/ if (node.isValueNode()) list.add(node.asText()); if (node.isArray()) { node.forEach((n) -> { if (n != null && (!n.isNull()) && (!n.isMissingNode()) && n.isValueNode()) list.add(n.toString()); }); } }
From source file:org.onosproject.ovsdbrest.OvsdbNodeConfig.java
public Set<OvsdbNode> getNodes() { Set<OvsdbNode> nodes = Sets.newConcurrentHashSet(); JsonNode jsnoNodes = object.path(NODES); jsnoNodes.forEach(node -> { IpAddress ovsdbIp = IpAddress.valueOf(node.path(OVSDB_IP).textValue()); TpPort port = TpPort.tpPort(Integer.parseInt(node.path(OVSDB_PORT).asText())); log.info("Ovsdb port: " + port.toString()); nodes.add(new OvsdbNode(ovsdbIp, port)); });/*from w ww . j a v a2s .c om*/ return nodes; }
From source file:com.ga2sa.utils.ArrayToStringDeserializer.java
@Override public String deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException, JsonProcessingException { List<String> array = new ArrayList<String>(); JsonNode tree = jsonParser.readValueAsTree(); if (tree.isArray()) { tree.forEach(obj -> array.add(obj.textValue())); } else {//from w ww . jav a 2s.c o m array.add(tree.textValue()); } return StringUtils.join(array, ","); }
From source file:com.ibm.watson.catalyst.jumpqa.trec.TrecReader.java
@Override public List<Trec> read(List<String> strings) { final List<Trec> result = new ArrayList<Trec>(); strings.stream().forEachOrdered((s) -> { try {//from w w w . j av a 2s. c o m final JsonNode corpus = MAPPER.readValue(s, JsonNode.class); final JsonNode trecs = corpus.get("documents"); trecs.forEach((trec) -> result.add(json2trec(trec))); } catch (final JsonParseException e) { throw new RuntimeException("Error while parsing.", e); } catch (final JsonMappingException e) { throw new RuntimeException("Error while mapping.", e); } catch (final IOException e) { throw new RuntimeException("IOError while parsing", e); } }); logger.fine("Read " + result.size() + " trecs"); return result; }
From source file:org.onosproject.icona.domainmgr.impl.config.DomainConfig.java
public Map<LinkId, Pair<Link.Type, ConnectPoint>> interlinkMap() { Map<LinkId, Pair<Link.Type, ConnectPoint>> map = new HashMap<>(); JsonNode domainElems = object.path(REMOTE_DOMAINS); // for each domain domainElems.forEach(domainElem -> { JsonNode interlinksJson = domainElem.path(INTER_LINK_PORTS); // for each interlink of a single domain interlinksJson.forEach(interlinkJson -> { LinkId linkId = LinkId.linkId(interlinkJson.path(LINK_ID).asText()); DeviceId deviceId = DeviceId.deviceId(interlinkJson.path(DEVICE_ID).asText()); PortNumber portNumber = PortNumber.fromString(interlinkJson.path(PORT_NUMBER).asText()); String type = interlinkJson.path(LINK_TYPE).asText(); Link.Type ilType;/*from ww w . ja va 2 s.co m*/ switch (type) { case "virtual": ilType = VIRTUAL; break; case "optical": ilType = OPTICAL; break; case "tunnel": ilType = TUNNEL; break; case "direct": ilType = DIRECT; break; default: ilType = INDIRECT; } map.put(linkId, Pair.of(ilType, new ConnectPoint(deviceId, portNumber))); }); }); return map; }
From source file:org.onosproject.icona.domainprovider.impl.config.IconaConfig.java
/** * Parses the list of peers from the configuration json object. * * @return set of domain configuration objects *///from w w w .jav a 2 s.c om public Set<DomainConfig> getPeersConfig() { Set<DomainConfig> peers = Sets.newHashSet(); JsonNode abstractionsNode = object.get(DOMAINS); abstractionsNode.forEach(peerNode -> { String id = peerNode.path(DOMAIN_ID).asText(); DomainId domainId = new DomainId(id); TopologyConfig.Type type; switch (peerNode.path(TOPOLOGY_TYPE).asText()) { case "bigSwitch": type = BIG_SWITCH; break; case "fullMesh": type = FULL_MESH; break; default: type = BIG_SWITCH; } ArrayList<String> endPointIds = new ArrayList<>(); peerNode.path(END_POINTS).forEach(endPointId -> endPointIds.add(endPointId.asText())); TopologyConfig topologyConfig = new TopologyConfig(type, endPointIds); peers.add(new DomainConfig(domainId, topologyConfig)); }); return peers; }