List of usage examples for com.fasterxml.jackson.databind JsonNode elements
public Iterator<JsonNode> elements()
From source file:com.ning.metrics.collector.util.LocalFileReader.java
public static void main(String[] args) throws IOException { InputStream stream = null;//from w ww. j a v a 2 s.c om try { stream = new BufferedInputStream(new FileInputStream(args[0])); final SmileEnvelopeEventDeserializer deserializer = new SmileEnvelopeEventDeserializer(stream, false); while (deserializer.hasNextEvent()) { final SmileEnvelopeEvent event = deserializer.getNextEvent(); final JsonNode node = (JsonNode) event.getData(); final Iterator<JsonNode> elements = node.elements(); boolean first = true; while (elements.hasNext()) { final JsonNode jsonNode = elements.next(); if (!first) { System.out.print(","); } System.out.print(jsonNode.toString()); first = false; } System.out.print("\n"); } } finally { if (stream != null) { stream.close(); } System.out.flush(); } }
From source file:com.enitalk.controllers.youtube.CalendarTest.java
public static void main(String[] args) throws IOException { InputStream is = new ClassPathResource("events.json").getInputStream(); ObjectMapper jackson = new ObjectMapper(); JsonNode tree = jackson.readTree(is); IOUtils.closeQuietly(is);/*from w ww .j a v a 2 s . co m*/ DateTimeFormatter fmtDateTime = ISODateTimeFormat.dateTimeNoMillis(); DateTimeFormatter fmt = ISODateTimeFormat.date(); TreeMultimap<DateTime, DateTime> set = CalendarTest.getPeriodSet(10, 18); Iterator<JsonNode> nodes = tree.elements(); while (nodes.hasNext()) { JsonNode ev = nodes.next(); boolean isFullDay = ev.path("start").has("date"); DateTime stDate = isFullDay ? fmt.parseDateTime(ev.path("start").path("date").asText()) : fmtDateTime.parseDateTime(ev.path("start").path("dateTime").asText()); DateTime enDate = isFullDay ? fmt.parseDateTime(ev.path("end").path("date").asText()) : fmtDateTime.parseDateTime(ev.path("end").path("dateTime").asText()); System.out.println("St " + stDate + " en " + enDate); int days = Days.daysBetween(stDate, enDate).getDays(); System.out.println("Days between " + days); if (isFullDay) { switch (days) { case 1: set.removeAll(stDate); break; default: while (days-- > 0) { set.removeAll(stDate.plusDays(days)); } } } else { DateTime copySt = stDate.minuteOfHour().setCopy(0).secondOfMinute().setCopy(0); DateTime copyEn = enDate.plusHours(1).minuteOfHour().setCopy(0).secondOfMinute().setCopy(0); // System.out.println("Dates truncated " + copySt + " " + copyEn); // System.out.println("Ll set " + set); // System.out.println("Getting set for key " + stDate.millisOfDay().setCopy(0)); SortedSet<DateTime> ss = set.get(stDate.millisOfDay().setCopy(0)); SortedSet<DateTime> subset = ss.subSet(copySt, copyEn); subset.clear(); set.remove(enDate.millisOfDay().setCopy(0), copyEn); } } }
From source file:com.reprezen.swaggerparser.test.ExamplesTest.java
@Parameters public static Collection<URL> findExamples() throws IOException { Collection<URL> examples = Lists.newArrayList(); Deque<URL> dirs = Queues.newArrayDeque(); String auth = System.getenv("GITHUB_AUTH") != null ? System.getenv("GITHUB_AUTH") + "@" : ""; String request = String.format("https://%sapi.github.com/repos/%s/contents/%s?ref=%s", auth, SPEC_REPO, EXAMPLES_ROOT, EXAMPLES_BRANCH); dirs.add(new URL(request)); while (!dirs.isEmpty()) { URL url = dirs.remove();/* ww w . ja va 2s . c o m*/ String json = IOUtils.toString(url, Charsets.UTF_8); JsonNode tree = mapper.readTree(json); for (JsonNode result : iterable(tree.elements())) { String type = result.get("type").asText(); String path = result.get("path").asText(); String resultUrl = result.get("url").asText(); if (type.equals("dir")) { dirs.add(new URL(resultUrl)); } else if (type.equals("file") && (path.endsWith(".yaml") || path.endsWith(".json"))) { String downloadUrl = result.get("download_url").asText(); examples.add(new URL(downloadUrl)); } } } return examples; }
From source file:mobile.vo.user.EducationExp.java
public static List<EducationExp> createList(Expert expert) { List<EducationExp> exp = new ArrayList<>(); if (null != expert && StringUtils.isNotBlank(expert.educationExp)) { JsonNode eduExpNode = Json.parse(expert.educationExp); if (eduExpNode.isArray()) { Iterator<JsonNode> elements = eduExpNode.elements(); while (elements.hasNext()) { JsonNode next = elements.next(); exp.add(create(next));/*from w w w . j ava 2 s. co m*/ } } } return exp; }
From source file:mobile.vo.user.JobExp.java
public static List<JobExp> createList(Expert expert) { List<JobExp> list = new ArrayList<>(); if (null != expert && StringUtils.isNotBlank(expert.jobExp)) { JsonNode expertJobExp = Json.parse(expert.jobExp); if (expertJobExp.isArray()) { Iterator<JsonNode> elements = expertJobExp.elements(); while (elements.hasNext()) { JsonNode next = elements.next(); list.add(create(next));//w w w . j a v a2 s .com } } } return list; }
From source file:org.opendaylight.atrium.hostservice.impl.ConfigReader.java
public static Addresses getArpAddresses() { if (rootJsonNode == null) { return null; }//from w w w . ja v a2 s . c o m JsonNode addressesJsonNode = rootJsonNode.path("addresses"); Iterator<JsonNode> addressesNodeIterator = addressesJsonNode.elements(); AddressesBuilder addressesBuilder = new AddressesBuilder(); List<Address> addressList = new ArrayList<Address>(); while (addressesNodeIterator.hasNext()) { AddressBuilder addressBuilder = new AddressBuilder(); JsonNode addressElementNode = addressesNodeIterator.next(); String hexDpid = addressElementNode.path("dpid").asText(); String dpid = AtriumUtils.hexDpidStringToOpenFlowDpid(hexDpid); NodeConnectorId port = new NodeConnectorId(addressElementNode.path("port").asText()); MacAddress mac = new MacAddress(addressElementNode.path("mac").asText()); JsonNode ipsJsonNode = addressElementNode.path("ips"); Iterator<JsonNode> ipsJsonNodeIterator = ipsJsonNode.elements(); IpAddress ips = null; if (ipsJsonNodeIterator.hasNext()) { JsonNode ipJsonNode = ipsJsonNodeIterator.next(); ips = new IpAddress(new Ipv4Address(ipJsonNode.asText().split("/")[0])); } int vlan = (int) addressElementNode.path("vlan").asLong(); if (vlan == 0) { vlan = 1; } AddressKey addressKey = new AddressKey(ips); addressBuilder.setDpid(dpid); addressBuilder.setOfPortId(port); addressBuilder.setMac(mac); addressBuilder.setIpAddress(ips); addressBuilder.setVlan(new Integer(vlan)); addressBuilder.setKey(addressKey); addressList.add(addressBuilder.build()); } addressesBuilder.setAddress(addressList); return addressesBuilder.build(); }
From source file:com.wegas.log.neo4j.Neo4jUtils.java
/** * Extracts from the JSON result of a query the potential error message. * If no message is found null is returned. * * @param result the result of the query * @return the error message if an error occurred, null otherwise */// w ww. ja v a 2 s .co m protected static String extractErrorData(String result) { ObjectMapper om = new ObjectMapper(); try { JsonNode jn = om.readTree(result); JsonNode jnErr = jn.path("errors"); Iterator<JsonNode> ite1 = jnErr.elements(); String err = ""; while (ite1.hasNext()) { JsonNode jn1 = ite1.next(); err += ", " + jn1.path("message").asText(); } if ("".equals(err)) return null; return err.substring(2); } catch (IOException ioe) { logger.debug("Error in extractErrorData: " + ioe.getMessage()); } return null; }
From source file:com.wegas.log.neo4j.Neo4jUtils.java
/** * Extracts the data part from the JSON result of a query. The data is * returned as a list of string(s). If no data was found, an empty list is * returned./*w ww. j ava 2 s . c o m*/ * * @param result the result of a query * @return the data list as a Json object */ protected static ArrayNode extractListData(String result) { ArrayNode on = objectMapper.createArrayNode(); ObjectMapper om = new ObjectMapper(); try { JsonNode jn = om.readTree(result); JsonNode jnRes = jn.path("results"); Iterator<JsonNode> ite1 = jnRes.elements(); while (ite1.hasNext()) { JsonNode jn1 = ite1.next(); JsonNode jnDat = jn1.path("data"); Iterator<JsonNode> ite2 = jnDat.elements(); while (ite2.hasNext()) { JsonNode jn2 = ite2.next(); JsonNode jnRow = jn2.path("row"); Iterator<JsonNode> ite3 = jnRow.elements(); while (ite3.hasNext()) { JsonNode jn3 = ite3.next(); on.add(jn3); } } } } catch (IOException ioe) { logger.debug("Error in extractListData: " + ioe.getMessage()); } return on; }
From source file:org.opendaylight.atrium.routingservice.config.ConfigReader.java
public static BgpPeers getBgpPeer() { if (rootJsonNode == null) { return null; }/*from ww w .j a va2 s . co m*/ JsonNode bgpPeersJsonNode = rootJsonNode.path("bgpPeers"); Iterator<JsonNode> bgpPeerNodeIterator = bgpPeersJsonNode.elements(); BgpPeersBuilder bgpPeersBuilder = new BgpPeersBuilder(); List<BgpPeer> bgpPeerList = new ArrayList<BgpPeer>(); while (bgpPeerNodeIterator.hasNext()) { BgpPeerBuilder bgpPeerBuilder = new BgpPeerBuilder(); JsonNode peerElementNode = bgpPeerNodeIterator.next(); IpAddress peerAddr = new IpAddress(new Ipv4Address(peerElementNode.path("ipAddress").asText())); String ofDpId = AtriumUtils .hexDpidStringToOpenFlowDpid(peerElementNode.path("attachmentDpid").asText()); NodeId peerDpId = new NodeId(ofDpId); Long peerPort = peerElementNode.path("attachmentPort").asLong(); BgpPeerKey peerKey = new BgpPeerKey(peerAddr); bgpPeerBuilder.setPeerAddr(peerAddr); bgpPeerBuilder.setPeerDpId(peerDpId); bgpPeerBuilder.setPeerPort(peerPort); bgpPeerBuilder.setKey(peerKey); bgpPeerList.add(bgpPeerBuilder.build()); } bgpPeersBuilder.setBgpPeer(bgpPeerList); return bgpPeersBuilder.build(); }
From source file:org.opendaylight.atrium.routingservice.config.ConfigReader.java
public static BgpSpeakers getBgpSpeakers() { if (rootJsonNode == null) { return null; }/*from w ww . java2 s . c o m*/ JsonNode bgpSpeakersJsonNode = rootJsonNode.path("bgpSpeakers"); Iterator<JsonNode> bgpSpeakerNodeIterator = bgpSpeakersJsonNode.elements(); BgpSpeakersBuilder bgpSpeakersBuilder = new BgpSpeakersBuilder(); List<BgpSpeaker> bgpSpeakerList = new ArrayList<BgpSpeaker>(); while (bgpSpeakerNodeIterator.hasNext()) { BgpSpeakerBuilder bgpSpeakerBuilder = new BgpSpeakerBuilder(); JsonNode speakerElementNode = bgpSpeakerNodeIterator.next(); String speakerName = speakerElementNode.path("name").asText(); String ofAttachmentDpId = AtriumUtils .hexDpidStringToOpenFlowDpid(speakerElementNode.path("attachmentDpid").asText()); long attachmentPort = speakerElementNode.path("attachmentPort").asLong(); MacAddress macAddress = new MacAddress(speakerElementNode.path("macAddress").asText()); NodeId attachmentDpId = new NodeId(ofAttachmentDpId); List<InterfaceAddresses> interfaceAddressesList = new ArrayList<InterfaceAddresses>(); BgpSpeakerKey bgpSpeakerKey = new BgpSpeakerKey(macAddress); Iterator<JsonNode> interfaceAddressesIterator = speakerElementNode.path("interfaceAddresses") .elements(); while (interfaceAddressesIterator.hasNext()) { InterfaceAddressesBuilder interfaceAddressesBuilder = new InterfaceAddressesBuilder(); JsonNode interfaceElementNode = interfaceAddressesIterator.next(); String ofNode = AtriumUtils .hexDpidStringToOpenFlowDpid(interfaceElementNode.path("interfaceDpid").asText()); String nodeConnectorString = ofNode + ":" + interfaceElementNode.path("interfacePort").asText(); IpAddress ipAddress = new IpAddress( new Ipv4Address(interfaceElementNode.path("ipAddress").asText())); NodeConnectorId of_port_id = new NodeConnectorId(nodeConnectorString); InterfaceAddressesKey addressesKey = new InterfaceAddressesKey(of_port_id); interfaceAddressesBuilder.setIpAddress(ipAddress); interfaceAddressesBuilder.setOfPortId(of_port_id); interfaceAddressesBuilder.setKey(addressesKey); interfaceAddressesList.add(interfaceAddressesBuilder.build()); } bgpSpeakerBuilder.setAttachmentPort(attachmentPort); bgpSpeakerBuilder.setMacAddress(macAddress); bgpSpeakerBuilder.setSpeakerName(speakerName); bgpSpeakerBuilder.setAttachmentDpId(attachmentDpId); bgpSpeakerBuilder.setInterfaceAddresses(interfaceAddressesList); bgpSpeakerBuilder.setKey(bgpSpeakerKey); bgpSpeakerList.add(bgpSpeakerBuilder.build()); } bgpSpeakersBuilder.setBgpSpeaker(bgpSpeakerList); return bgpSpeakersBuilder.build(); }