List of usage examples for com.fasterxml.jackson.databind JsonNode elements
public Iterator<JsonNode> elements()
From source file:com.omertron.themoviedbapi.methods.TmdbCertifications.java
/** * Get a list of tv certification./*w w w . j a va 2s . com*/ * * @return * @throws MovieDbException */ public ResultsMap<String, List<Certification>> getTvCertification() throws MovieDbException { URL url = new ApiUrl(apiKey, MethodBase.CERTIFICATION).subMethod(MethodSub.TV_LIST).buildUrl(); String webpage = httpTools.getRequest(url); try { JsonNode node = MAPPER.readTree(webpage); Map<String, List<Certification>> results = MAPPER.readValue(node.elements().next().traverse(), new TypeReference<Map<String, List<Certification>>>() { }); return new ResultsMap<String, List<Certification>>(results); } catch (IOException ex) { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get TV certifications", url, ex); } }
From source file:com.omertron.themoviedbapi.methods.TmdbCertifications.java
/** * Get a list of movies certification./*from ww w .j av a2 s . c om*/ * * @return * @throws MovieDbException */ public ResultsMap<String, List<Certification>> getMoviesCertification() throws MovieDbException { URL url = new ApiUrl(apiKey, MethodBase.CERTIFICATION).subMethod(MethodSub.MOVIE_LIST).buildUrl(); String webpage = httpTools.getRequest(url); try { JsonNode node = MAPPER.readTree(webpage); Map<String, List<Certification>> results = MAPPER.readValue(node.elements().next().traverse(), new TypeReference<Map<String, List<Certification>>>() { }); return new ResultsMap<String, List<Certification>>(results); } catch (IOException ex) { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get movie certifications", url, ex); } }
From source file:com.github.restdriver.matchers.WithValueAt.java
@Override public boolean matchesSafely(JsonNode node) { if (!node.isArray()) { return false; }/* w w w .jav a 2s . c o m*/ Iterator<JsonNode> nodeIterator = node.elements(); int nodeCount = 0; while (nodeIterator.hasNext()) { JsonNode currentNode = nodeIterator.next(); if (nodeCount == position) { return matcher.matches(currentNode.textValue()); } nodeCount++; } return false; }
From source file:de.ks.flatadocdb.defaults.DefaultEntityPersister.java
@Override public Object load(Repository repository, EntityDescriptor descriptor, Path path, Map<Relation, Collection<String>> relationIds) { try {//from w w w .jav a2s.c o m JsonNode jsonNode = mapper.readTree(path.toFile()); descriptor.getAllRelations().forEach(rel -> { String name = rel.getRelationField().getName(); JsonNode jsonValue = jsonNode.findValue(name); if (jsonValue.elements().hasNext()) { jsonValue = jsonValue.elements().next(); } ArrayList<String> ids = new ArrayList<>(); relationIds.put(rel, ids); if (jsonValue.isContainerNode()) { jsonValue.elements().forEachRemaining(id -> ids.add(id.asText())); } else if (!jsonValue.isNull()) { ids.add(jsonValue.asText()); } log.debug("Found {} relation id's in {}: {}", ids.size(), name, ids); }); return mapper.readValue(path.toFile(), descriptor.getEntityClass()); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.redhat.lightblue.util.test.AbstractJsonNodeTest.java
public boolean arrayNodesHaveSameValues(JsonNode expected, JsonNode actual) { int i = 0;/* www . ja v a 2s.c o m*/ for (Iterator<JsonNode> nodes = expected.elements(); nodes.hasNext(); i++) { JsonNode node = nodes.next(); if (node instanceof TextNode) { return textNodesHaveSameValue(node, actual.get(i)); } else if (node instanceof IntNode) { return intNodesHaveSameValue(node, actual.get(i)); } else if (node instanceof DoubleNode) { return doubleNodesHaveSameValue(node, actual.get(i)); } } return true; }
From source file:de.kaixo.mubi.lists.store.MubiListsToElasticSearchLoader.java
public void loadFromJson(Path path) { logger.info("Processing " + path.toString()); try {/*from w w w . jav a 2 s . co m*/ JsonNode node = mapper.readTree(path.toFile()); if (node.isArray()) { node.elements().forEachRemaining(elem -> { StringWriter writer = new StringWriter(); try { JsonGenerator generator = factory.createGenerator(writer); mapper.writeTree(generator, elem); client.prepareIndex(INDEX_NAME, TYPE).setSource(writer.toString()).get(); } catch (IOException e) { logger.error("Failed to write item", e); } }); } } catch (IOException e) { logger.error("Failed to process " + path.toString(), e); } }
From source file:com.hp.autonomy.frontend.find.core.search.QueryRestrictionsDeserializer.java
protected <T> List<T> parseArray(@SuppressWarnings("TypeMayBeWeakened") final JsonNode node, final String fieldName, final NodeParser<T> parser) { final List<T> fields = new ArrayList<>(); final JsonNode arrayNode = node.get(fieldName); if (arrayNode != null) { final Iterator<JsonNode> iterator = arrayNode.elements(); while (iterator.hasNext()) { fields.add(parser.parse(iterator.next())); }/* w w w .j av a 2s.c o m*/ } return fields; }
From source file:org.neo4j.ogm.drivers.http.response.AbstractHttpResponse.java
private void initialise() { try {// w w w . j a v a 2s. c o m responseNode = mapper.readTree(buffer.asParser()); LOGGER.debug("Response: {}", responseNode); JsonNode errors = responseNode.findValue("errors"); if (errors.elements().hasNext()) { JsonNode errorNode = errors.elements().next(); throw new CypherException("Error executing Cypher " + errorNode.findValue("code"), errorNode.findValue("code").asText(), errorNode.findValue("message").asText()); } } catch (IOException e) { throw new ResultProcessingException("Error processing results", e); } }
From source file:com.sg2net.utilities.ListaCAP.json.ComuneDeserializer.java
@Override public Comune deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { ObjectMapper mapper = (ObjectMapper) jsonParser.getCodec(); ObjectNode root = (ObjectNode) mapper.readTree(jsonParser); JsonNode codiceIstatNode = root.get("codiceIstat"); String codiceIstat = codiceIstatNode.asText(); JsonNode codiceCatastaleNode = root.get("codiceCatastale"); String codiceCatastale = codiceCatastaleNode.asText(); JsonNode nomeNode = root.get("nome"); String nome = nomeNode.asText(); JsonNode provinciaNode = root.get("provincia"); String provincia = provinciaNode.asText(); JsonNode codiciCapNode = root.get("codiciCap"); Collection<String> codiciCap = new ArrayList<>(); Iterator<JsonNode> capNodes = codiciCapNode.elements(); while (capNodes.hasNext()) { JsonNode codiceCapNode = capNodes.next(); String codiceCap = codiceCapNode.asText(); codiciCap.add(codiceCap);//from ww w.j a v a 2 s .c o m } Comune comune = new Comune(codiceIstat, codiceCatastale, nome, provincia); comune.setCodiciCap(codiciCap); logger.trace("comune =" + comune + " deserializzato from json"); return comune; }
From source file:io.gravitee.definition.jackson.datatype.services.healthcheck.deser.ExpectationDeserializer.java
@Override public Expectation deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonNode node = jp.getCodec().readTree(jp); Expectation expectation = new Expectation(); final JsonNode assertionsNode = node.get("assertions"); if (assertionsNode != null) { List<String> assertions = new ArrayList<>(); assertionsNode.elements().forEachRemaining(assertionNode -> assertions.add(assertionNode.asText())); expectation.setAssertions(assertions); }//w w w .j av a 2 s . co m if (expectation.getAssertions().isEmpty()) { // Add default assertion expectation.setAssertions(Collections.singletonList(Expectation.DEFAULT_ASSERTION)); } return expectation; }