本文整理了Java中com.fasterxml.jackson.databind.JsonNode.elements()
方法的一些代码示例,展示了JsonNode.elements()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.elements()
方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.JsonNode
类名称:JsonNode
方法名:elements
[英]Method for accessing all value nodes of this Node, iff this node is a JSON Array or Object node. In case of Object node, field names (keys) are not included, only values. For other types of nodes, returns empty iterator.
[中]方法访问此节点的所有值节点,如果此节点是JSON数组或对象节点。对于对象节点,不包括字段名(键),仅包括值。对于其他类型的节点,返回空迭代器。
代码示例来源:origin: aws/aws-sdk-java
private static List<JmesPathExpression> getChildren(JsonNode jsonNode){
if(jsonNode.get("children").size() < 1) {
throw new RuntimeException("Expected one or more arguments");
}
Iterator<JsonNode> children = jsonNode.get("children").elements();
final List<JmesPathExpression> childrenList = new ArrayList<>();
while (children.hasNext()) {
childrenList.add(fromAstJsonToAstJava(children.next()));
}
return childrenList;
}
代码示例来源:origin: stagemonitor/stagemonitor
@Test
public void reportSpan() throws Exception {
reporter.report(mock(SpanContextInformation.class), getSpan(100));
elasticsearchClient.waitForCompletion();
refresh();
final JsonNode hits = elasticsearchClient.getJson("/stagemonitor-spans*/_search").get("hits");
assertThat(hits.get("total").intValue()).as(hits.toString()).isEqualTo(1);
final JsonNode spanJson = hits.get("hits").elements().next().get("_source");
assertThat(spanJson.get("type").asText()).as(spanJson.toString()).isEqualTo("jdbc");
assertThat(spanJson.get("method").asText()).as(spanJson.toString()).isEqualTo("SELECT");
assertThat(spanJson.get("db.statement")).as(spanJson.toString()).isNotNull();
assertThat(spanJson.get("db.statement").asText()).as(spanJson.toString()).isEqualTo("SELECT * from STAGEMONITOR where 1 < 2");
assertThat(spanJson.get("duration_ms").asInt()).as(spanJson.toString()).isEqualTo(100);
assertThat(spanJson.get("name").asText()).as(spanJson.toString()).isEqualTo("ElasticsearchExternalSpanReporterIntegrationTest#test");
}
代码示例来源:origin: org.jasig.portal/uPortal-groups-pags
@Override
public Set<IPersonAttributesGroupDefinition> deserialize(
JsonParser jsonParser, DeserializationContext ctx)
throws JsonProcessingException, IOException {
ObjectCodec oc = jsonParser.getCodec();
JsonNode node = oc.readTree(jsonParser);
// For now, we'll only support deserializing PAGS definitions WITHOUT members...
if (node.elements().hasNext()) {
throw new UnsupportedOperationException("Members not yet supported");
}
return Collections.emptySet();
}
}
代码示例来源:origin: Alluxio/alluxio
/**
* Deserialize an AccessControlList object.
* @param jsonParser the json parser
* @param deserializationContext deserializationcontext
* @return
* @throws IOException
* @throws JsonProcessingException
*/
@Override
public AccessControlList deserialize(JsonParser jsonParser,
DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
String owner = node.get(OWNER_FIELD).asText();
String owningGroup = node.get(OWNING_GROUP_FIELD).asText();
List<String> stringEntries = new ArrayList<>();
Iterator<JsonNode> nodeIterator = node.get(STRING_ENTRY_FIELD).elements();
while (nodeIterator.hasNext()) {
stringEntries.add(nodeIterator.next().asText());
}
return AccessControlList.fromStringEntries(owner, owningGroup, stringEntries);
}
}
代码示例来源:origin: stagemonitor/stagemonitor
@Test
public void testUpdateSpan() throws Exception {
final Span span = tracer.buildSpan("Test#test")
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
.start();
span.finish();
elasticsearchClient.waitForCompletion();
refresh();
reporter.updateSpan(B3HeaderFormat.getB3Identifiers(tracer, span), null, Collections.singletonMap("foo", "bar"));
refresh();
final JsonNode hits = elasticsearchClient.getJson("/stagemonitor-spans*/_search").get("hits");
assertThat(hits.get("total").intValue()).as(hits.toString()).isEqualTo(1);
final JsonNode spanJson = hits.get("hits").elements().next().get("_source");
assertThat(spanJson.get("foo").asText()).as(spanJson.toString()).isEqualTo("bar");
}
代码示例来源:origin: Jasig/uPortal
@Override
public Set<IPersonAttributesGroupDefinition> deserialize(
JsonParser jsonParser, DeserializationContext ctx)
throws JsonProcessingException, IOException {
ObjectCodec oc = jsonParser.getCodec();
JsonNode node = oc.readTree(jsonParser);
// For now, we'll only support deserializing PAGS definitions WITHOUT members...
if (node.elements().hasNext()) {
throw new UnsupportedOperationException("Members not yet supported");
}
return Collections.emptySet();
}
}
代码示例来源:origin: liferay/liferay-portal
public List<String> getCurrentObject() throws NoSuchElementException {
JsonNode resourceJsonNode = _inputRecordsJsonNode.get(
_inputRecordsIndex);
if (resourceJsonNode == null) {
_log.error("Index: {}", _inputRecordsIndex);
throw new NoSuchElementException("Index: " + _inputRecordsIndex);
}
List<String> resourceValues = new ArrayList<>();
Iterator<JsonNode> iterator = resourceJsonNode.elements();
while (iterator.hasNext()) {
JsonNode jsonNode = iterator.next();
resourceValues.add(jsonNode.toString());
}
if (_log.isDebugEnabled()) {
_log.debug("Resource has been processed");
}
return resourceValues;
}
代码示例来源:origin: stagemonitor/stagemonitor
@Test
public void testUpdateNotYetExistentSpan_eventuallyUpdates() throws Exception {
final Span span = tracer.buildSpan("Test#test")
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
.start();
reporter.updateSpan(B3HeaderFormat.getB3Identifiers(tracer, span), null, Collections.singletonMap("foo", "bar"));
span.finish();
elasticsearchClient.waitForCompletion();
refresh();
reporter.getUpdateReporter().flush();
refresh();
final JsonNode hits = elasticsearchClient.getJson("/stagemonitor-spans*/_search").get("hits");
assertThat(hits.get("total").intValue()).as(hits.toString()).isEqualTo(1);
final JsonNode spanJson = hits.get("hits").elements().next().get("_source");
assertThat(spanJson.get("foo").asText()).as(spanJson.toString()).isEqualTo("bar");
}
代码示例来源:origin: aws/aws-sdk-java
/**
* If subject is an array, this function returns true if
* one of the elements in the array is equal to the provided search
* value.
*
* @param subject Array
* @param search JmesPath expression
* @return True array contains search;
* False otherwise
*/
private static BooleanNode doesArrayContain(JsonNode subject, JsonNode search) {
Iterator<JsonNode> elements = subject.elements();
while (elements.hasNext()) {
if (elements.next().equals(search)) {
return BooleanNode.TRUE;
}
}
return BooleanNode.FALSE;
}
代码示例来源:origin: stagemonitor/stagemonitor
@Test
public void reportSpan() throws Exception {
final Map<String, String> parameters = new HashMap<>();
parameters.put("attr.Color", "Blue");
parameters.put("attr", "bla");
parameters.put("foo", "bar");
final Span span = tracer.buildSpan("Test#test")
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
.start();
SpanUtils.setParameters(span, parameters);
span.setTag(SpanUtils.OPERATION_TYPE, "method_invocation");
span.setTag("foo.bar", "baz");
span.finish();
elasticsearchClient.waitForCompletion();
refresh();
final JsonNode hits = elasticsearchClient.getJson("/stagemonitor-spans*/_search").get("hits");
assertThat(hits.get("total").intValue()).as(hits.toString()).isEqualTo(1);
validateSpanJson(hits.get("hits").elements().next().get("_source"));
}
代码示例来源:origin: docker-java/docker-java
@Override
public Binds deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
throws IOException, JsonProcessingException {
List<Bind> binds = new ArrayList<Bind>();
ObjectCodec oc = jsonParser.getCodec();
JsonNode node = oc.readTree(jsonParser);
for (Iterator<JsonNode> it = node.elements(); it.hasNext();) {
JsonNode field = it.next();
binds.add(Bind.parse(field.asText()));
}
return new Binds(binds.toArray(new Bind[0]));
}
}
代码示例来源:origin: org.apache.drill.exec/drill-java-exec
@Override
public DynamicPojoRecordReader convert(JsonNode value) {
LinkedHashMap<String, Class<?>> schema = mapper.convertValue(value.get("schema"), schemaType);
ArrayList records = new ArrayList(schema.size());
final Iterator<JsonNode> recordsIterator = value.get("records").get(0).elements();
for (Class<?> fieldType : schema.values()) {
records.add(mapper.convertValue(recordsIterator.next(), fieldType));
}
int maxRecordsToRead = value.get("recordsPerBatch").asInt();
return new DynamicPojoRecordReader(schema, Collections.singletonList(records), maxRecordsToRead);
}
}
代码示例来源:origin: prestodb/presto
@Override
public RangeBoundValue deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException
{
JsonNode node = jp.getCodec().readTree(jp);
if (node.isNull()) {
return null;
}
else {
List<Object> list;
if (node.isArray()) {
list = new ArrayList<>();
Iterator<JsonNode> iter = node.elements();
while (iter.hasNext()) {
Object v = toValue(iter.next());
list.add(v);
}
}
else {
Object v = toValue(node);
list = ImmutableList.of(v);
}
return new RangeBoundValue(list);
}
}
代码示例来源:origin: liferay/liferay-portal
public static boolean hasValueOf(String value, JsonNode jsonNode) {
if (jsonNode.isArray()) {
Iterator<JsonNode> iterator = jsonNode.elements();
while (iterator.hasNext()) {
JsonNode entryJsonNode = iterator.next();
String entry = entryJsonNode.asText();
if (entry.equals(value)) {
return true;
}
}
}
else if (jsonNode.isValueNode()) {
String entry = jsonNode.asText();
if (entry.equals(value)) {
return true;
}
}
return false;
}
代码示例来源:origin: joelittlejohn/jsonschema2pojo
private Map<String, JFieldVar> removeFieldsExcludedFromEqualsAndHashCode(Map<String, JFieldVar> fields, JsonNode node) {
Map<String, JFieldVar> filteredFields = new HashMap<>(fields);
JsonNode properties = node.get("properties");
if (properties != null) {
if (node.has("excludedFromEqualsAndHashCode")) {
JsonNode excludedArray = node.get("excludedFromEqualsAndHashCode");
for (Iterator<JsonNode> iterator = excludedArray.elements(); iterator.hasNext(); ) {
String excludedPropertyName = iterator.next().asText();
JsonNode excludedPropertyNode = properties.get(excludedPropertyName);
filteredFields.remove(ruleFactory.getNameHelper().getPropertyName(excludedPropertyName, excludedPropertyNode));
}
}
for (Iterator<Map.Entry<String, JsonNode>> iterator = properties.fields(); iterator.hasNext(); ) {
Map.Entry<String, JsonNode> entry = iterator.next();
String propertyName = entry.getKey();
JsonNode propertyNode = entry.getValue();
if (propertyNode.has("excludedFromEqualsAndHashCode") &&
propertyNode.get("excludedFromEqualsAndHashCode").asBoolean()) {
filteredFields.remove(ruleFactory.getNameHelper().getPropertyName(propertyName, propertyNode));
}
}
}
return filteredFields;
}
代码示例来源:origin: aws/aws-sdk-java
Entry<String, JsonNode> principal;
Iterator<JsonNode> elements;
while (mapOfPrincipals.hasNext()) {
principal = mapOfPrincipals.next();
schema = principal.getKey();
principalNode = principal.getValue();
elements = principalNode.elements();
while (elements.hasNext()) {
principals.add(createPrincipal(schema, elements.next()));
代码示例来源:origin: docker-java/docker-java
@Override
public Links deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext)
throws IOException, JsonProcessingException {
final List<Link> binds = new ArrayList<Link>();
final ObjectCodec oc = jsonParser.getCodec();
final JsonNode node = oc.readTree(jsonParser);
for (final Iterator<JsonNode> it = node.elements(); it.hasNext();) {
final JsonNode element = it.next();
if (!element.equals(NullNode.getInstance())) {
binds.add(Link.parse(element.asText()));
}
}
return new Links(binds.toArray(new Link[0]));
}
}
代码示例来源:origin: SeldonIO/seldon-server
Iterator<JsonNode> iter = prediction.get("predictions").elements();
double bestScore = 0;
String bestClass = null;
while (iter.hasNext())
JsonNode jPred = iter.next();
double score = jPred.get("prediction").asDouble();
String predClass = jPred.get("predictedClass").asText();
代码示例来源:origin: spring-projects/spring-data-redis
private void flattenElement(String propertyPrefix, Object source, Map<String, Object> resultMap) {
if (!(source instanceof JsonNode)) {
resultMap.put(propertyPrefix, source);
return;
}
JsonNode element = (JsonNode) source;
if (element.isArray()) {
Iterator<JsonNode> nodes = element.elements();
while (nodes.hasNext()) {
JsonNode cur = nodes.next();
if (cur.isArray()) {
this.falttenCollection(propertyPrefix, cur.elements(), resultMap);
}
}
} else if (element.isContainerNode()) {
this.doFlatten(propertyPrefix, element.fields(), resultMap);
} else {
resultMap.put(propertyPrefix, new DirectFieldAccessFallbackBeanWrapper(element).getPropertyValue("_value"));
}
}
代码示例来源:origin: apache/incubator-pinot
private static void removeValue(JsonNode jsonArray, String value) {
Iterator<JsonNode> elements = jsonArray.elements();
while (elements.hasNext()) {
if (elements.next().asText().equals(value)) {
elements.remove();
return;
}
}
}
}
内容来源于网络,如有侵权,请联系作者删除!