List of usage examples for com.fasterxml.jackson.databind JsonNode elements
public Iterator<JsonNode> elements()
From source file:com.baidubce.services.moladb.model.transform.WriteRequestListUnmarshaller.java
@Override public List<WriteRequest> unmarshall(JsonNode root) throws Exception { List<WriteRequest> list = new ArrayList<WriteRequest>(); Iterator<JsonNode> reqs = root.elements(); while (reqs.hasNext()) { WriteRequestUnmarshaller unmarshaller = new WriteRequestUnmarshaller(); WriteRequest writeReq = unmarshaller.unmarshall(reqs.next()); list.add(writeReq);// w ww . j a v a 2 s . c o m } return list; }
From source file:com.baidubce.services.moladb.model.transform.KeysAndAttributesUnmarshaller.java
private List<String> deserializeAttributes(JsonNode jsonObj) { List<String> attributes = new ArrayList<String>(); Iterator<JsonNode> elements = jsonObj.elements(); while (elements.hasNext()) { attributes.add(elements.next().asText()); }//ww w .j a v a2s .com return attributes; }
From source file:com.baidubce.services.moladb.model.transform.KeysAndAttributesUnmarshaller.java
private List<Key> deserializeKeys(JsonNode jsonObj) throws Exception { List<Key> keyList = new ArrayList<Key>(); Iterator<JsonNode> keys = jsonObj.elements(); while (keys.hasNext()) { KeyUnmarshaller unmarshaller = new KeyUnmarshaller(); Key key = unmarshaller.unmarshall(keys.next()); keyList.add(key);// w ww.j a v a2 s . c om } return keyList; }
From source file:io.gravitee.definition.jackson.datatype.api.deser.PathDeserializer.java
@Override public Path deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonNode node = jp.getCodec().readTree(jp); Path pathDefinition = new Path(); if (node.isArray()) { node.elements().forEachRemaining(jsonNode -> { try { Rule rule = jsonNode.traverse(jp.getCodec()).readValueAs(Rule.class); pathDefinition.getRules().add(rule); } catch (IOException e) { e.printStackTrace();/*from w w w .java 2 s.c o m*/ } }); } return pathDefinition; }
From source file:alpine.json.TrimmedStringArrayDeserializer.java
@Override public String[] deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException { final List<String> list = new ArrayList<>(); final JsonNode node = jsonParser.readValueAsTree(); if (node.isArray()) { final Iterator elements = node.elements(); while (elements.hasNext()) { final JsonNode childNode = (JsonNode) elements.next(); final String value = StringUtils.trimToNull(childNode.asText()); if (value != null) { list.add(value);//from w ww . j a va 2s .co m } } } if (list.size() == 0) { return null; } else { return list.toArray(new String[list.size()]); } }
From source file:com.enitalk.controllers.bots.FillWordsRunnable.java
public void sendCandidates(String url, Integer type) { try {/*from w w w. jav a2s . c o m*/ Response json = Request.Get(url).execute(); String rs = json.returnContent().asString(); JsonNode randomContent = jackson.readTree(rs); Iterator<JsonNode> els = randomContent.elements(); while (els.hasNext()) { ObjectNode el = (ObjectNode) els.next(); if (Character.isUpperCase(el.path("word").asText().charAt(0)) || StringUtils.contains(el.path("word").asText(), " ")) { els.remove(); } else { el.put("type", type); rabbit.send("words", MessageBuilder.withBody(jackson.writeValueAsBytes(el)).build()); } } } catch (Exception e) { logger.error(ExceptionUtils.getFullStackTrace(e)); } }
From source file:com.github.restdriver.matchers.ContainingValue.java
@Override public boolean matchesSafely(JsonNode node) { if (!node.isArray()) { return false; }//from w ww . ja va 2 s. com Iterator<JsonNode> nodeIterator = node.elements(); while (nodeIterator.hasNext()) { String value = nodeIterator.next().textValue(); if (matcher.matches(value)) { return true; } } return false; }
From source file:la.alsocan.jsonshapeshifter.schemas.SchemaObjectNode.java
protected SchemaObjectNode withResolvedChildren(JsonNode node) { JsonNode props = node.get("properties"); // untyped objects not supported if (props == null) { throw new UnsupportedJsonSchemaException("Untyped objects are currently not supported"); }/*from www. j ava 2s . c om*/ // collect required element names Set<String> reqSet = new HashSet<>(); JsonNode reqs = node.get("required"); if (reqs != null) { Iterator<JsonNode> itReqs = reqs.elements(); while (itReqs.hasNext()) { reqSet.add(itReqs.next().asText()); } } // build children elements Iterator<String> itName = props.fieldNames(); Iterator<JsonNode> itNode = props.elements(); while (itNode.hasNext()) { String childName = itName.next(); SchemaNode typedChild = buildSchemaNode(itNode.next(), childName, path + "/" + childName, reqSet.contains(childName)); children.add(typedChild); typedChild.setParent(this); } return this; }
From source file:org.fcrepo.camel.reindexing.RestProcessor.java
/** * Convert the incoming REST request into the correct * Fcrepo header fields./* w ww . ja va 2s. com*/ * * @param exchange the current message exchange */ public void process(final Exchange exchange) throws Exception { final Message in = exchange.getIn(); final String path = in.getHeader(Exchange.HTTP_PATH, "", String.class); final String contentType = in.getHeader(Exchange.CONTENT_TYPE, "", String.class); final String body = in.getBody(String.class); final Set<String> endpoints = new HashSet<>(); for (final String s : in.getHeader(ReindexingHeaders.RECIPIENTS, "", String.class).split(",")) { endpoints.add(s.trim()); } in.removeHeaders("CamelHttp*"); in.removeHeader("JMSCorrelationID"); in.setBody(null); if (contentType.equals("application/json") && body != null && !body.trim().isEmpty()) { final ObjectMapper mapper = new ObjectMapper(); try { final JsonNode root = mapper.readTree(body); final Iterator<JsonNode> ite = root.elements(); while (ite.hasNext()) { final JsonNode n = ite.next(); endpoints.add(n.asText()); } } catch (JsonProcessingException e) { LOGGER.debug("Invalid JSON", e); in.setHeader(Exchange.HTTP_RESPONSE_CODE, BAD_REQUEST); in.setBody("Invalid JSON"); } } in.setHeader(FcrepoHeaders.FCREPO_IDENTIFIER, path); in.setHeader(ReindexingHeaders.RECIPIENTS, String.join(",", endpoints)); }
From source file:com.baidubce.services.moladb.model.transform.ItemListUnmarshaller.java
@Override public List<Map<String, AttributeValue>> unmarshall(JsonNode listObj) throws Exception { List<Map<String, AttributeValue>> itemList = new ArrayList<Map<String, AttributeValue>>(); Iterator<JsonNode> itemObjs = listObj.elements(); while (itemObjs.hasNext()) { JsonNode itemObj = itemObjs.next(); ItemUnmarshaller itemUnmarshaller = new ItemUnmarshaller(); Map<String, AttributeValue> item = itemUnmarshaller.unmarshall(itemObj); itemList.add(item);/*from w ww . j av a 2 s .c om*/ } return itemList; }