com.fasterxml.jackson.databind.JsonNode.isContainerNode()方法的使用及代码示例

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

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

JsonNode.isContainerNode介绍

[英]Method that returns true for container nodes: Arrays and Objects.

Note: one and only one of methods #isValueNode, #isContainerNode and #isMissingNode ever returns true for any given node.
[中]方法,该方法为容器节点(数组和对象)返回true。
注意:对于任何给定节点,方法#isValueNode、#isContainerNode和#isMissingNode中只有一个会返回true。

代码示例

代码示例来源:origin: apache/hbase

public static JsonNode searchJson(JsonNode tree, String searchKey)
  throws JsonProcessingException, IOException {
 if (tree == null) {
  return null;
 }
 if(tree.has(searchKey)) {
  return tree.get(searchKey);
 }
 if(tree.isContainerNode()) {
  for(JsonNode branch: tree) {
   JsonNode branchResult = searchJson(branch, searchKey);
   if (branchResult != null && !branchResult.isMissingNode()) {
    return branchResult;
   }
  }
 }
 return null;
}

代码示例来源:origin: apache/pulsar

@Override
  public Object getField(String fieldName) {
    JsonNode fn = jn.get(fieldName);
    if (fn.isContainerNode()) {
      AtomicInteger idx = new AtomicInteger(0);
      List<Field> fields = Lists.newArrayList(fn.fieldNames())
        .stream()
        .map(f -> new Field(f, idx.getAndIncrement()))
        .collect(Collectors.toList());
      return new GenericJsonRecord(fields, fn);
    } else if (fn.isBoolean()) {
      return fn.asBoolean();
    } else if (fn.isInt()) {
      return fn.asInt();
    } else if (fn.isFloatingPointNumber()) {
      return fn.asDouble();
    } else if (fn.isDouble()) {
      return fn.asDouble();
    } else {
      return fn.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: Graylog2/graylog2-server

if (value.isContainerNode()) {
  fieldValue = value.toString();
} else if (value.isFloatingPointNumber()) {

代码示例来源:origin: aws/aws-sdk-java

if (valueNode == null || !valueNode.isContainerNode()) {
  return valueNode;

代码示例来源:origin: java-json-tools/json-schema-validator

if (node.isContainerNode()) {
  if (node.isArray())
    processArray(report, data);

代码示例来源:origin: com.redhat.lightblue/lightblue-core-util

@Override
  protected boolean hasChildren(JsonNode node) {
    return node.isContainerNode() && node.size() > 0;
  }
}

代码示例来源:origin: com.redhat.lightblue/util

@Override
  protected boolean hasChildren(JsonNode node) {
    return node.isContainerNode() && node.size() > 0;
  }
}

代码示例来源:origin: org.nuxeo.ecm.automation/nuxeo-automation-core

/**
 * @since 5.8-HF01
 */
private String extractValueFromNode(JsonNode node, ObjectMapper om) throws IOException {
  if (!node.isNull()) {
    return node.isContainerNode() ? om.writeValueAsString(node) : node.asText();
  } else {
    return null;
  }
}

代码示例来源:origin: com.qmetric/halreader

private void readProperties(MutableRepresentation resource, JsonNode rootNode) throws IOException {
  Iterator<String> fieldNames = rootNode.fieldNames();
  while (fieldNames.hasNext()) {
    String fieldName = fieldNames.next();
    if (!Support.RESERVED_JSON_PROPERTIES.contains(fieldName)) {
      JsonNode field = rootNode.get(fieldName);
      resource.withProperty(fieldName, field.isNull()
                       ? null
                       : ( field.isContainerNode() ? field.toString() : field.asText()));
    }
  }
}

代码示例来源:origin: jasminb/jsonapi-converter

/**
 * Returns <code>true</code> in case 'DATA' note has 'ID' and 'TYPE' attributes.
 * @param dataNode relationship data node
 * @return <code>true</code> if node has required attributes, else <code>false</code>
 */
public static boolean isRelationshipParsable(JsonNode dataNode) {
  return dataNode != null && dataNode.hasNonNull(JSONAPISpecConstants.ID) && dataNode.hasNonNull(JSONAPISpecConstants.TYPE) &&
      !dataNode.get(JSONAPISpecConstants.ID).isContainerNode() && !dataNode.get(JSONAPISpecConstants.TYPE).isContainerNode();
}

代码示例来源:origin: com.github.jasminb/jsonapi-converter

/**
 * Returns <code>true</code> in case 'DATA' note has 'ID' and 'TYPE' attributes.
 * @param dataNode relationship data node
 * @return <code>true</code> if node has required attributes, else <code>false</code>
 */
public static boolean isRelationshipParsable(JsonNode dataNode) {
  return dataNode != null && dataNode.hasNonNull(JSONAPISpecConstants.ID) && dataNode.hasNonNull(JSONAPISpecConstants.TYPE) &&
      !dataNode.get(JSONAPISpecConstants.ID).isContainerNode() && !dataNode.get(JSONAPISpecConstants.TYPE).isContainerNode();
}

代码示例来源:origin: gengstrand/clojure-news-feed

private void extract(String attributeName, JsonNode node, List<Long> results) {
  JsonNode n = node.get(attributeName);
  if (n != null) {
    Long l = n.asLong();
    if (!results.contains(l)) {
      results.add(l);
    }
  }
  if (node.isContainerNode()) {
    toList(node.elements()).stream().forEach(cn -> extract(attributeName, cn, results));
  }
}

代码示例来源:origin: com.github.fge/jackson-coreutils

@Override
public JsonNode get(final JsonNode node)
{
  if (node == null || !node.isContainerNode())
    return null;
  final String raw = token.getRaw();
  return node.isObject() ? node.get(raw) : node.get(arrayIndexFor(raw));
}

代码示例来源:origin: com.github.java-json-tools/jackson-coreutils

@Override
public JsonNode get(final JsonNode node)
{
  if (node == null || !node.isContainerNode())
    return null;
  final String raw = token.getRaw();
  return node.isObject() ? node.get(raw) : node.get(arrayIndexFor(raw));
}

代码示例来源:origin: line/centraldogma

void valueAdded(final JsonPointer pointer, final JsonNode value) {
  final JsonPatchOperation op;
  if (value.isContainerNode()) {
    // Use copy operation only for container nodes.
    final JsonPointer ptr = findUnchangedValue(value);
    op = ptr != null ? new CopyOperation(ptr, pointer)
             : new AddOperation(pointer, value);
  } else {
    op = new AddOperation(pointer, value);
  }
  diffs.add(op);
}

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common

void valueAdded(final JsonPointer pointer, final JsonNode value) {
  final JsonPatchOperation op;
  if (value.isContainerNode()) {
    // Use copy operation only for container nodes.
    final JsonPointer ptr = findUnchangedValue(value);
    op = ptr != null ? new CopyOperation(ptr, pointer)
             : new AddOperation(pointer, value);
  } else {
    op = new AddOperation(pointer, value);
  }
  diffs.add(op);
}

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common-shaded

void valueAdded(final JsonPointer pointer, final JsonNode value) {
  final JsonPatchOperation op;
  if (value.isContainerNode()) {
    // Use copy operation only for container nodes.
    final JsonPointer ptr = findUnchangedValue(value);
    op = ptr != null ? new CopyOperation(ptr, pointer)
             : new AddOperation(pointer, value);
  } else {
    op = new AddOperation(pointer, value);
  }
  diffs.add(op);
}

代码示例来源:origin: com.blackducksoftware.magpie/magpie-test

/**
 * Fails if the subject is not a container with the specified number of values or name/value pairs.
 */
public void hasLength(int length) {
  // TODO Support string length?
  checkArgument(length >= 0, "length (%s) must be >= 0", length);
  if (actual() == null || !actual().isContainerNode()) {
    fail("is a container");
  } else if (actual().size() != length) {
    fail("has length", length);
  }
}

代码示例来源:origin: com.blackducksoftware.magpie/magpie-test

/**
 * Fails if the subject is a container with one ore more values or name/value pairs.
 */
public void isEmpty() {
  if (actual() == null || !actual().isContainerNode()) {
    fail("is a container");
  } else if (actual().size() != 0) {
    fail("is empty");
  }
}

相关文章