org.codehaus.jackson.JsonNode.getElements()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(92)

本文整理了Java中org.codehaus.jackson.JsonNode.getElements()方法的一些代码示例,展示了JsonNode.getElements()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.getElements()方法的具体详情如下:
包路径:org.codehaus.jackson.JsonNode
类名称:JsonNode
方法名:getElements

JsonNode.getElements介绍

[英]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: org.codehaus.jackson/jackson-mapper-asl

public Array(JsonNode n, NodeCursor p) {
  super(JsonStreamContext.TYPE_ARRAY, p);
  _contents = n.getElements();
}

代码示例来源:origin: org.codehaus.jackson/jackson-core-asl

/**
 * Same as calling {@link #getElements}; implemented so that
 * convenience "for-each" loop can be used for looping over elements
 * of JSON Array constructs.
 */
@Override
public final Iterator<JsonNode> iterator() { return getElements(); }

代码示例来源:origin: kaaproject/kaa

private static JsonNode injectUuidsFromJsonNodes(JsonNode json, Schema schema) {
 if (json == null) {
  return json;
 }
 switch (schema.getType()) {
  case RECORD:
   schema.getFields().stream()
     .filter(f -> !f.name().equals(UUID_FIELD))
     .forEach(f -> injectUuidsFromJsonNodes(json.get(f.name()), f.schema()));
   boolean addressable = schema.getFields().stream().filter(f -> f.name().equals(
       UUID_FIELD)).findFirst().isPresent();
   if (addressable) {
    ((ObjectNode) json).put(UUID_FIELD, (Integer) null);
   }
   break;
  case UNION:
   schema.getTypes()
     .forEach(s -> injectUuidsFromJsonNodes(json.get(s.getName()), s));
   break;
  case ARRAY:
   json.getElements().forEachRemaining((elem) -> injectUuids(elem, schema.getElementType()));
   break;
  default:
   return json;
 }
 return json;
}

代码示例来源:origin: azkaban/azkaban

} else if (node.isArray()) {
 final ArrayList<Object> array = new ArrayList<>();
 final Iterator<JsonNode> iter = node.getElements();
 while (iter.hasNext()) {
  final JsonNode element = iter.next();

代码示例来源:origin: apache/incubator-gobblin

@Test
public void testToJson() throws IOException {
 GlobalMetadata m = new GlobalMetadata();
 m.addTransferEncoding("foo");
 m.addTransferEncoding("bar");
 byte[] utf8 = m.toJsonUtf8();
 String parsed = new String(utf8, StandardCharsets.UTF_8);
 JsonNode root = new ObjectMapper().readTree(parsed);
 Assert.assertTrue(root.isObject());
 Iterator<JsonNode> children = root.getElements();
 int numChildren = 0;
 while (children.hasNext()) {
  children.next();
  numChildren++;
 }
 Assert.assertEquals(numChildren, 3, "expected only 3 child nodes - file, dataset, id");
 Assert.assertEquals(root.get("file").size(), 0, "expected no children in file node");
 Assert.assertTrue(root.get("id").isTextual(), "expected ID to be textual");
 JsonNode transferEncoding = root.get("dataset").get("Transfer-Encoding");
 Assert.assertEquals(transferEncoding.size(), m.getTransferEncoding().size());
 for (int i = 0; i < m.getTransferEncoding().size(); i++) {
  Assert.assertEquals(transferEncoding.get(i).getTextValue(), m.getTransferEncoding().get(i));
 }
}

代码示例来源:origin: kaaproject/kaa

/**
  * Removes UUIDs from a json tree.
  *
  * @param json json tree node
  */
 public static void removeUuids(JsonNode json) {
  boolean containerWithId = json.isContainerNode() && json.has(UUID_FIELD);
  boolean isArray = json.isArray();
  boolean childIsNotArray = !(json.size() == 1 && json.getElements().next().isArray());

  if (containerWithId && !isArray && childIsNotArray) {
   ((ObjectNode) json).remove(UUID_FIELD);
  }

  for (JsonNode node : json) {
   if (node.isContainerNode()) {
    removeUuids(node);
   }
  }
 }
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * Same as calling {@link #getElements}; implemented so that
 * convenience "for-each" loop can be used for looping over elements
 * of JSON Array constructs.
 */
@Override
public final Iterator<JsonNode> iterator() { return getElements(); }

代码示例来源:origin: camunda/camunda-bpm-platform

public Array(JsonNode n, NodeCursor p) {
  super(JsonStreamContext.TYPE_ARRAY, p);
  _contents = n.getElements();
}

代码示例来源:origin: stackoverflow.com

abstract class BaseTickets {
  String ticketType;
  public String getTicketType()
}

public class MyListDeserializer extends JsonDeserializer<BaseTickets> {

  @Override
  public BaseTickets deserialize(JsonParser jsonParser, DeserializationContext arg1) throws IOException, JsonProcessingException {
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    Iterator<JsonNode> elements = node.getElements();
    for (; elements.hasNext();) {
      String type = (String) elements.next().get("ticketType");

      if (type.equals()){
        //create concrete type here
      }
    }
   }

代码示例来源:origin: youseries/urule

@Override
  public List<Rule> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    ObjectCodec oc = jp.getCodec();
    JsonNode jsonNode = oc.readTree(jp);
    Iterator<JsonNode> childrenNodesIter=jsonNode.getElements();
    List<Rule> rules=new ArrayList<Rule>();
    while(childrenNodesIter.hasNext()){
      JsonNode childNode=childrenNodesIter.next();
      rules.add(parseRule(jp,childNode));
    }
    return rules;
  }
}

代码示例来源:origin: klout/brickhouse

@Override
public Object parseJson(JsonNode jsonNode) {
  if (jsonNode.isNull())
    return null;
  List newList = (List) retInspector.create(0);
  Iterator<JsonNode> listNodes = jsonNode.getElements();
  while (listNodes.hasNext()) {
    JsonNode elemNode = listNodes.next();
    if (elemNode != null) {
      Object elemObj = elemHandle.parseJson(elemNode);
      newList.add(elemObj);
    } else {
      newList.add(null);
    }
  }
  return newList;
}

代码示例来源:origin: youseries/urule

private MultiCondition parseMultiCondition(JsonNode multiConditionNode) {
  MultiCondition condition=new MultiCondition();
  condition.setType(JunctionType.valueOf(JsonUtils.getJsonValue(multiConditionNode, "type")));
  Iterator<JsonNode> iter=multiConditionNode.get("conditions").getElements();
  while(iter.hasNext()){
    JsonNode propertyCriteriaNode=iter.next();
    PropertyCriteria pc=new PropertyCriteria();
    pc.setOp(Op.valueOf(JsonUtils.getJsonValue(propertyCriteriaNode, "op")));
    pc.setProperty(JsonUtils.getJsonValue(propertyCriteriaNode, "property"));
    pc.setValue(JsonUtils.parseValue(propertyCriteriaNode));
    condition.addCondition(pc);
  }
  return condition;
}

代码示例来源:origin: youseries/urule

JsonNode jsonNode = mapper.readTree(jsonParser);
List<FlowNode> flowNodes=new ArrayList<FlowNode>();
Iterator<JsonNode> childrenNodesIter=jsonNode.getElements();
while(childrenNodesIter.hasNext()){
  JsonNode childNode=childrenNodesIter.next();
    decisionNode.setDecisionType(decisionType);
    JsonNode itemsNode=childNode.get("items");
    Iterator<JsonNode> iter=itemsNode.getElements();
    List<DecisionItem> items=new ArrayList<DecisionItem>();
    while(iter.hasNext()){
  if(connectionsNode!=null){
    List<Connection> connections=new ArrayList<Connection>();
    Iterator<JsonNode> iter=connectionsNode.getElements();
    while(iter.hasNext()){
      JsonNode connNode=iter.next();

代码示例来源:origin: com.barchart.wrap/barchart-wrap-jackson

/**
 * Same as calling {@link #getElements}; implemented so that
 * convenience "for-each" loop can be used for looping over elements
 * of JSON Array constructs.
 */
public final Iterator<JsonNode> iterator() { return getElements(); }

代码示例来源:origin: youseries/urule

JsonNode jsonNode = oc.readTree(jsonParser);
List<ReteNode> reteNodes=new ArrayList<ReteNode>();
Iterator<JsonNode> childrenNodesIter=jsonNode.getElements();
while(childrenNodesIter.hasNext()){
  JsonNode childNode=childrenNodesIter.next();

代码示例来源:origin: org.mule.modules/mule-module-json

public JsonNode[] toArray() 
{
  List<JsonNode> children = new ArrayList<JsonNode>();
  for (Iterator<JsonNode> itr = node.getElements(); itr.hasNext();) 
  {
    children.add(itr.next());
  }
  return children.toArray(new JsonNode[children.size()]);
}

代码示例来源:origin: lordofthejars/nosql-unit

private Iterator<JsonNode> dataElements(InputStream dataStream) throws IOException, JsonParseException,
    JsonMappingException {
  JsonNode rootNode = OBJECT_MAPPER.readValue(dataStream, JsonNode.class);
  JsonNode dataNode = rootNode.path(KeyValueTokens.DATA_TOKEN);
  Iterator<JsonNode> elements = dataNode.getElements();
  return elements;
}

代码示例来源:origin: com.datasalt.pangool/pangool-core

public static Criteria parse(JsonNode node) throws IOException {
 Iterator<JsonNode> elements = node.getElements();
 List<SortElement> sorts = new ArrayList<SortElement>();
 while (elements.hasNext()) {
  sorts.add(SortElement.parse(elements.next()));
 }
 return new Criteria(sorts);
}

代码示例来源:origin: lordofthejars/nosql-unit

private Object readArray(JsonNode value, String implementationValue) throws IOException, JsonParseException,
    JsonMappingException, ClassNotFoundException {
  Object readObject;
  Iterator<JsonNode> elements = value.getElements();
  Collection<Object> objects = collection(implementationValue);
  
  while (elements.hasNext()) {
    JsonNode newElement = elements.next();
    objects.add(readValue(newElement));
  }
  readObject = objects;
  return readObject;
}

代码示例来源:origin: com.lordofthejars/nosqlunit-core

private Object readArray(JsonNode value, String implementationValue) throws IOException, JsonParseException,
    JsonMappingException, ClassNotFoundException {
  Object readObject;
  Iterator<JsonNode> elements = value.getElements();
  Collection<Object> objects = collection(implementationValue);
  
  while (elements.hasNext()) {
    JsonNode newElement = elements.next();
    objects.add(readValue(newElement));
  }
  readObject = objects;
  return readObject;
}

相关文章