本文整理汇总了Java中com.fasterxml.jackson.databind.JsonNode.forEach方法的典型用法代码示例。如果您正苦于以下问题:Java JsonNode.forEach方法的具体用法?Java JsonNode.forEach怎么用?Java JsonNode.forEach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.JsonNode
的用法示例。
在下文中一共展示了JsonNode.forEach方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bgpPeer
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Returns the set of nodes read from network config.
*
* @return list of BgpPeerConfig or null
*/
public List<BgpPeerConfig> bgpPeer() {
List<BgpPeerConfig> nodes = new ArrayList<BgpPeerConfig>();
JsonNode jsonNodes = object.get(BGP_PEER);
if (jsonNodes == null) {
return null;
}
jsonNodes.forEach(jsonNode -> nodes.add(new BgpPeerConfig(
jsonNode.path(PEER_IP).asText(),
jsonNode.path(REMOTE_AS).asInt(),
jsonNode.path(PEER_HOLD_TIME).asInt(),
jsonNode.path(PEER_CONNECT_MODE).asText())));
return nodes;
}
示例2: parseLibrary
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private BuckLibrary parseLibrary(Map.Entry<String, JsonNode> entry) {
String libraryName = entry.getKey();
JsonNode list = entry.getValue();
if (list.size() == 0) {
throw new RuntimeException("Empty library: " + libraryName);
}
List<String> libraryTargets = new ArrayList<>(list.size());
list.forEach(node -> {
String name;
if (node.isObject()) {
name = node.get("name").asText();
} else if (node.isTextual()) {
name = node.asText();
} else {
throw new RuntimeException("Unknown node type: " + node.getNodeType());
}
if (!name.contains(":")) {
name = ':' + name;
}
libraryTargets.add(name);
});
return BuckLibrary.getLibrary(libraryName, libraryTargets);
}
示例3: providerServices
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public Set<VtnServiceId> providerServices(VtnServiceId tServiceId) {
checkNotNull(tServiceId);
String response = restGet(tServiceId.id());
log.trace("Get provider services {}", response);
ObjectMapper mapper = new ObjectMapper();
Set<VtnServiceId> pServices = Sets.newHashSet();
try {
JsonNode nodes = mapper.readTree(response);
nodes.forEach(node -> pServices.add(VtnServiceId.of(node.asText())));
} catch (IOException e) {
log.warn("Failed to get service dependency");
}
return pServices;
}
示例4: nodes
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Returns the data plane IP map of nodes read from network config.
*
* @return data plane IP map
*/
public Map<DeviceId, Ip4Address> nodes() {
Map<DeviceId, Ip4Address> nodeMap = Maps.newHashMap();
JsonNode jsonNodes = object.get(NODES);
if (jsonNodes == null) {
log.error("There's no node information");
return null;
}
jsonNodes.forEach(jsonNode -> {
try {
nodeMap.putIfAbsent(DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText()),
Ip4Address.valueOf(jsonNode.path(DATAPLANE_IP).asText()));
} catch (IllegalArgumentException | NullPointerException e) {
log.error("Failed to read {}", e.toString());
}
});
return nodeMap;
}
示例5: localIp4PrefixEntries
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Gets the set of configured local IPv4 prefixes.
*
* @return IPv4 prefixes
*/
public Set<LocalIpPrefixEntry> localIp4PrefixEntries() {
Set<LocalIpPrefixEntry> prefixes = Sets.newHashSet();
JsonNode prefixesNode = object.get(IP4LOCALPREFIXES);
if (prefixesNode == null) {
log.warn("ip4LocalPrefixes is null!");
return prefixes;
}
prefixesNode.forEach(jsonNode -> {
prefixes.add(new LocalIpPrefixEntry(
IpPrefix.valueOf(jsonNode.get(IPPREFIX).asText()),
IpPrefixType.valueOf(jsonNode.get(TYPE).asText()),
IpAddress.valueOf(jsonNode.get(GATEWAYIP).asText())));
});
return prefixes;
}
示例6: localIp6PrefixEntries
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Gets the set of configured local IPv6 prefixes.
*
* @return IPv6 prefixes
*/
public Set<LocalIpPrefixEntry> localIp6PrefixEntries() {
Set<LocalIpPrefixEntry> prefixes = Sets.newHashSet();
JsonNode prefixesNode = object.get(IP6LOCALPREFIXES);
if (prefixesNode == null) {
log.warn("ip6LocalPrefixes is null!");
return prefixes;
}
prefixesNode.forEach(jsonNode -> {
prefixes.add(new LocalIpPrefixEntry(
IpPrefix.valueOf(jsonNode.get(IPPREFIX).asText()),
IpPrefixType.valueOf(jsonNode.get(TYPE).asText()),
IpAddress.valueOf(jsonNode.get(GATEWAYIP).asText())));
});
return prefixes;
}
示例7: addPeerToSpeaker
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Adds peering address to BGP speaker.
*
* @param speakerName name of BGP speaker
* @param peerAddress peering address to be added
*/
public void addPeerToSpeaker(String speakerName, IpAddress peerAddress) {
JsonNode speakersNode = object.get(SPEAKERS);
speakersNode.forEach(jsonNode -> {
if (jsonNode.hasNonNull(NAME) &&
jsonNode.get(NAME).asText().equals(speakerName)) {
ArrayNode peersNode = (ArrayNode) jsonNode.get(PEERS);
for (int i = 0; i < peersNode.size(); i++) {
if (peersNode.get(i).asText().equals(peerAddress.toString())) {
return; // Peer already exists.
}
}
peersNode.add(peerAddress.toString());
}
});
}
示例8: removePeerFromSpeaker
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Removes peering address from BGP speaker.
*
* @param speaker BGP speaker configuration entries
* @param peerAddress peering address to be removed
*/
public void removePeerFromSpeaker(BgpSpeakerConfig speaker, IpAddress peerAddress) {
JsonNode speakersNode = object.get(SPEAKERS);
speakersNode.forEach(jsonNode -> {
if (jsonNode.hasNonNull(NAME) &&
jsonNode.get(NAME).asText().equals(speaker.name().get())) {
ArrayNode peersNode = (ArrayNode) jsonNode.get(PEERS);
for (int i = 0; i < peersNode.size(); i++) {
if (peersNode.get(i).asText().equals(peerAddress.toString())) {
peersNode.remove(i);
return;
}
}
}
});
}
示例9: gatewayNodes
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Returns the set of nodes read from network config.
*
* @return set of OpensatckNodeConfig or null
*/
public Set<GatewayNode> gatewayNodes() {
Set<GatewayNode> nodes = Sets.newHashSet();
JsonNode jsonNodes = object.get(NODES);
if (jsonNodes == null) {
return null;
}
jsonNodes.forEach(jsonNode -> {
try {
nodes.add(new GatewayNode.Builder()
.gatewayDeviceId(DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText()))
.gatewayExternalInterfaceNames(
getExternalInterfaceName(jsonNode.path(EXTERNAL_INTERFACE_NAME).asText()))
.dataIpAddress(Ip4Address.valueOf(jsonNode.path(DATAPLANE_IP).asText())).build());
} catch (IllegalArgumentException | NullPointerException e) {
log.error("Failed to read {}", e.toString());
}
});
return nodes;
}
示例10: test02
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Test
public void test02() throws Exception {
//49
ObjectMapper mapper = new ObjectMapper();
List<String> ret = new ArrayList<>();
String url = "https://xueqiu.com/stock/cata/stocklist.json?page=";
String param = "&size=100&order=desc&orderby=percent&type=11%2C12&_=1461851096446";
for (int i = 1; i <= 50; i++) {
String dest = url + i + param;
HttpRequest req = HttpRequest.get(dest);
req.header("Cookie", "xq_a_token=93b9123bccf67168e3adb0c07d89b9e1f6cc8db6;");
String body = req.body();
ret.add(body);
JsonNode jsonNode = mapper.readTree(body);
JsonNode stocks = jsonNode.get("stocks");
stocks.forEach(st->{
Stock stock = null;
try {
stock = mapper.readValue(st.toString(), Stock.class);
DaoUtil.dao.insert(stock);
} catch (Exception e) {
e.printStackTrace();
}
});
Thread.sleep(500);
System.out.println("fetch url " + dest + " result " + body);
}
System.out.println("final result---> " + mapper.writeValueAsString(ret));
}
示例11: extractDeviceIds
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Extracts device ids from a given JSON string.
*
* @param stream deviceIds JSON stream
* @return a set of device identifiers
* @throws IOException
*/
private Set<DeviceId> extractDeviceIds(InputStream stream) throws IOException {
ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
JsonNode deviceIdsJson = jsonTree.get("deviceIds");
if (deviceIdsJson == null || deviceIdsJson.size() == 0) {
throw new IllegalArgumentException(DEVICE_IDS_INVALID);
}
Set<DeviceId> deviceIds = Sets.newHashSet();
deviceIdsJson.forEach(did -> deviceIds.add(DeviceId.deviceId(did.asText())));
return deviceIds;
}
示例12: deleteFlows
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Removes a batch of flow rules.
*
* @param stream stream for posted JSON
* @return 204 NO CONTENT
*/
@DELETE
public Response deleteFlows(InputStream stream) {
ListMultimap<DeviceId, Long> deviceMap = ArrayListMultimap.create();
List<FlowEntry> rulesToRemove = new ArrayList<>();
try {
ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
JsonNode jsonFlows = jsonTree.get("flows");
jsonFlows.forEach(node -> {
DeviceId deviceId =
DeviceId.deviceId(
nullIsNotFound(node.get(DEVICE_ID),
DEVICE_NOT_FOUND).asText());
long flowId = nullIsNotFound(node.get(FLOW_ID),
FLOW_NOT_FOUND).asLong();
deviceMap.put(deviceId, flowId);
});
} catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
deviceMap.keySet().forEach(deviceId -> {
List<Long> flowIds = deviceMap.get(deviceId);
Iterable<FlowEntry> entries = service.getFlowEntries(deviceId);
flowIds.forEach(flowId -> {
StreamSupport.stream(entries.spliterator(), false)
.filter(entry -> flowId == entry.id().value())
.forEach(rulesToRemove::add);
});
});
service.removeFlowRules(rulesToRemove.toArray(new FlowEntry[0]));
return Response.noContent().build();
}
示例13: processes
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Returns list of OSPF process from the json nodes.
*
* @param jsonNodes represents one or more OSPF process configuration
* @return list of OSPF processes.
*/
public static List<OspfProcess> processes(JsonNode jsonNodes) {
List<OspfProcess> ospfProcesses = new ArrayList<>();
if (jsonNodes == null) {
return ospfProcesses;
}
//From each Process nodes, get area and related interface details.
jsonNodes.forEach(jsonNode -> {
List<OspfArea> areas = new ArrayList<>();
//Get configured areas for the process.
for (JsonNode areaNode : jsonNode.path(AREAS)) {
List<OspfInterface> interfaceList = new ArrayList<>();
for (JsonNode interfaceNode : areaNode.path(INTERFACE)) {
OspfInterface ospfInterface = interfaceDetails(interfaceNode);
if (ospfInterface != null) {
interfaceList.add(ospfInterface);
}
}
//Get the area details
OspfArea area = areaDetails(areaNode);
if (area != null) {
area.setOspfInterfaceList(interfaceList);
areas.add(area);
}
}
OspfProcess process = new OspfProcessImpl();
process.setProcessId(jsonNode.path(PROCESSID).asText());
process.setAreas(areas);
ospfProcesses.add(process);
});
return ospfProcesses;
}
示例14: getIps
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private List<InterfaceIpAddress> getIps(JsonNode node) {
List<InterfaceIpAddress> ips = Lists.newArrayList();
JsonNode ipsNode = node.get(IPS);
if (ipsNode != null) {
ipsNode.forEach(jsonNode ->
ips.add(InterfaceIpAddress.valueOf(jsonNode.asText())));
}
return ips;
}
示例15: bgpSpeakers
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Gets the set of configured BGP speakers.
*
* @return BGP speakers
*/
public Set<BgpSpeakerConfig> bgpSpeakers() {
Set<BgpSpeakerConfig> speakers = Sets.newHashSet();
JsonNode speakersNode = object.get(SPEAKERS);
if (speakersNode == null) {
return speakers;
}
speakersNode.forEach(jsonNode -> {
Set<IpAddress> listenAddresses = Sets.newHashSet();
jsonNode.path(PEERS).forEach(addressNode ->
listenAddresses.add(IpAddress.valueOf(addressNode.asText()))
);
Optional<String> name;
if (jsonNode.get(NAME) == null) {
name = Optional.empty();
} else {
name = Optional.of(jsonNode.get(NAME).asText());
}
VlanId vlan = getVlan(jsonNode);
speakers.add(new BgpSpeakerConfig(name,
vlan,
ConnectPoint.deviceConnectPoint(jsonNode.path(CONNECT_POINT).asText()),
listenAddresses));
});
return speakers;
}