List of usage examples for com.fasterxml.jackson.databind JsonNode elements
public Iterator<JsonNode> elements()
From source file:com.rusticisoftware.tincan.Group.java
public Group(JsonNode jsonNode) { super(jsonNode); JsonNode memberNode = jsonNode.path("member"); if (!memberNode.isMissingNode()) { this.members = new ArrayList<Agent>(); Iterator it = memberNode.elements(); while (it.hasNext()) { this.members.add(Agent.fromJson((JsonNode) it.next())); }/*from w w w. j av a 2 s . c o m*/ } }
From source file:org.workspace7.moviestore.utils.MovieDBHelper.java
/** * This method queries the external API and caches the movies, for the demo purpose we just query only first page * * @return - the status code of the invocation *//*from w w w . jav a 2 s .c o m*/ protected int queryAndCache() { if (this.moviesCache.isEmpty()) { log.info("No movies exist in cache, loading cache .."); UriComponentsBuilder moviesUri = UriComponentsBuilder .fromUriString(movieStoreProps.getApiEndpointUrl() + "/movie/popular") .queryParam("api_key", movieStoreProps.getApiKey()); final URI requestUri = moviesUri.build().toUri(); log.info("Request URI:{}", requestUri); ResponseEntity<String> response = restTemplate.getForEntity(requestUri, String.class); log.info("Response Status:{}", response.getStatusCode()); Map<String, Movie> movieMap = new HashMap<>(); if (200 == response.getStatusCode().value()) { String jsonBody = response.getBody(); ObjectMapper objectMapper = new ObjectMapper(); try { JsonNode root = objectMapper.readTree(jsonBody); JsonNode results = root.path("results"); results.elements().forEachRemaining(movieNode -> { String id = movieNode.get("id").asText(); Movie movie = Movie.builder().id(id).overview(movieNode.get("overview").asText()) .popularity(movieNode.get("popularity").floatValue()) .posterPath("http://image.tmdb.org/t/p/w92" + movieNode.get("poster_path").asText()) .logoPath("http://image.tmdb.org/t/p/w45" + movieNode.get("poster_path").asText()) .title(movieNode.get("title").asText()) .price(ThreadLocalRandom.current().nextDouble(1.0, 10.0)).build(); movieMap.put(id, movie); }); } catch (IOException e) { log.error("Error reading response:", e); } log.debug("Got {} movies", movieMap); moviesCache.putAll(movieMap); } return response.getStatusCode().value(); } else { log.info("Cache already loaded with movies ... will use cache"); return 200; } }
From source file:io.moo.propane.sources.ClasspathFileConfigurationSource.java
private Object map(final JsonNode input) { if (input.isArray()) { Iterator<JsonNode> elements = input.elements(); List<Object> values = new ArrayList<>(); while (elements.hasNext()) { Optional.of(elements.next()).filter(JsonNode::isValueNode).map(JsonNode::asText) .ifPresent(values::add); }/* w w w . ja v a 2s.c o m*/ return values; } else if (input.isObject()) { System.out.println("Inception:"); final Iterator<Map.Entry<String, JsonNode>> fields = input.fields(); while (fields.hasNext()) { System.out.println(fields.next()); } return input.asText(); } else if (input.isValueNode()) { return input.asText(); } else { return input; } }
From source file:org.springframework.social.facebook.api.impl.UserTemplate.java
private List<String> deserializePermissionsNodeToList(JsonNode jsonNode) { JsonNode dataNode = jsonNode.get("data"); List<String> permissions = new ArrayList<String>(); for (Iterator<JsonNode> elementIt = dataNode.elements(); elementIt.hasNext();) { JsonNode permissionsElement = elementIt.next(); String name = permissionsElement.get("permission").asText(); String status = permissionsElement.get("status").asText(); if ("granted".equals(status)) { permissions.add(name);//from w ww .jav a2 s.c o m } } return permissions; }
From source file:org.jsonschema2pojo.rules.NotRequiredRule.java
/** * Applies this schema rule to take the not required code generation steps. * <p>//from www .j ava 2s .c o m * The not required rule adds a Nullable annotation if JSR-305 annotations are desired. * * @param nodeName * the name of the schema node for which this "required" rule has * been added * @param node * the "not required" node, having a value <code>false</code> or * <code>no value</code> * @param generatableType * the class or method which may be marked as "not required" * @return the JavaDoc comment attached to the generatableType, which * <em>may</em> have an added not to mark this construct as * not required. */ @Override public JDocCommentable apply(String nodeName, JsonNode node, JDocCommentable generatableType, Schema schema) { // Since NotRequiredRule is executed for all fields that do not have "required" present, // we need to recognize whether the field is part of the RequiredArrayRule. JsonNode requiredArray = schema.getContent().get("required"); if (requiredArray != null) { for (Iterator<JsonNode> iterator = requiredArray.elements(); iterator.hasNext();) { String requiredArrayItem = iterator.next().asText(); if (nodeName.equals(requiredArrayItem)) { return generatableType; } } } if (ruleFactory.getGenerationConfig().isIncludeJsr305Annotations() && generatableType instanceof JFieldVar) { generatableType.javadoc().append(NOT_REQUIRED_COMMENT_TEXT); ((JFieldVar) generatableType).annotate(Nullable.class); } return generatableType; }
From source file:org.agorava.facebook.impl.UserServiceImpl.java
private List<String> deserializePermissionsNodeToList(JsonNode jsonNode) { JsonNode dataNode = jsonNode.get("data"); List<String> permissions = new ArrayList<String>(); for (Iterator<JsonNode> elementIt = dataNode.elements(); elementIt.hasNext();) { JsonNode permissionsElement = elementIt.next(); for (Iterator<String> fieldNamesIt = permissionsElement.fieldNames(); fieldNamesIt.hasNext();) { permissions.add(fieldNamesIt.next()); }/*from www. jav a2 s. c o m*/ } return permissions; }
From source file:io.gravitee.definition.jackson.datatype.services.healthcheck.deser.RequestDeserializer.java
@Override public Request deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonNode node = jp.getCodec().readTree(jp); Request request = new Request(); JsonNode uriNode = node.get("uri"); if (uriNode != null) { request.setUri(uriNode.asText()); } else {//from w w w . ja va2 s .c o m throw ctxt.mappingException("[healthcheck] URI is required"); } final JsonNode methodNode = node.get("method"); if (methodNode != null) { request.setMethod(HttpMethod.valueOf(methodNode.asText().toUpperCase())); } else { throw ctxt.mappingException("[healthcheck] Method is required"); } JsonNode bodyNode = node.get("body"); if (bodyNode != null) { request.setBody(bodyNode.asText()); } JsonNode headersNode = node.get("headers"); if (headersNode != null) { List<HttpHeader> headers = new ArrayList<>(); headersNode.elements().forEachRemaining(headerNode -> { HttpHeader header = new HttpHeader(); header.setName(headerNode.findValue("name").asText()); header.setValue(headerNode.findValue("value").asText()); headers.add(header); }); request.setHeaders(headers); } return request; }
From source file:com.enitalk.configs.BotConfig.java
@Bean(name = "offsetMap") public TreeMap<Long, String> timezones() throws IOException { ObjectMapper j = new ObjectMapper(); JsonNode o = j.readTree(new ClassPathResource("dates/treeTz.json").getInputStream()); TreeMap<Long, String> offsets = new TreeMap<>(); Iterator<JsonNode> it = o.elements(); while (it.hasNext()) { JsonNode el = it.next();/*from ww w . ja v a 2s.c o m*/ String key = el.fieldNames().next(); offsets.put(Long.valueOf(key), el.path(key).iterator().next().toString()); } return offsets; }
From source file:com.nebhale.jsonpath.internal.component.WildcardPathComponent.java
@Override protected JsonNode select(JsonNode input) { if (input.isArray()) { return input; } else {//from w w w . ja v a 2 s. com ArrayNode result = JsonNodeFactory.instance.arrayNode(); for (Iterator<JsonNode> i = input.elements(); i.hasNext();) { result.add(i.next()); } return result; } }
From source file:com.strategicgains.hyperexpress.serialization.siren.jackson.SirenResourceDeserializer.java
/** * @param resource// ww w. j a v a 2 s . c om * @param field */ private void addAllLinks(SirenResource resource, Entry<String, JsonNode> field) { LinkBuilder lb = new LinkBuilder(); lb.rel(field.getKey()); Iterator<JsonNode> values = field.getValue().elements(); while (values.hasNext()) { JsonNode value = values.next(); Iterator<JsonNode> elements = value.elements(); while (elements.hasNext()) { JsonNode element = elements.next(); lb.set(element.asText(), element.textValue()); } resource.addLink(lb.build()); lb.clearAttributes(); } }