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

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

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

JsonNode.isMissingNode介绍

[英]Method that returns true for "virtual" nodes which represent missing entries constructed by path accessor methods when there is no actual node matching given criteria.

Note: one and only one of methods #isValueNode, #isContainerNode and #isMissingNode ever returns true for any given node.
[中]方法,当没有实际节点匹配给定条件时,该方法为“虚拟”节点返回true,这些节点表示由路径访问器方法构造的缺失项。
注意:对于任何给定节点,方法#isValueNode、#isContainerNode和#isMissingNode中只有一个会返回true。

代码示例

代码示例来源:origin: prestodb/presto

@Override
public final boolean isNull()
{
  return value.isMissingNode() || value.isNull();
}

代码示例来源:origin: prestodb/presto

@Override
public final boolean isNull()
{
  return value.isMissingNode() || value.isNull();
}

代码示例来源:origin: prestodb/presto

@Override
public boolean isNull()
{
  return value.isMissingNode() || value.isNull();
}

代码示例来源:origin: opentripplanner/OpenTripPlanner

private String serializedConfiguration(JsonNode config) throws JsonProcessingException{
  ObjectMapper mapper = new ObjectMapper();
  ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
  return config.isMissingNode() ? null : writer.writeValueAsString(config);
}

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

protected boolean isEqualToCurrentLocalizationValue(String language,
                          String id,
                          String propertyName,
                          String propertyValue,
                          ObjectNode infoNode) {
  boolean isEqual = false;
  JsonNode localizationNode = infoNode.path("localization").path(language).path(id).path(propertyName);
  if (!localizationNode.isMissingNode() && !localizationNode.isNull() && localizationNode.asText().equals(propertyValue)) {
    isEqual = true;
  }
  return isEqual;
}

代码示例来源:origin: liferay/liferay-portal

protected JsonNode findJsonNode(JsonNode resource, String nodeName) {
  JsonNode jsonNode = resource.path(nodeName);
  if (_log.isDebugEnabled()) {
    if (jsonNode.isMissingNode()) {
      _log.debug("Unable to find the \"{}\" node", nodeName);
    }
    if (jsonNode.isArray() && (jsonNode.size() == 0)) {
      _log.debug("The \"{}\" array node is empty", jsonNode);
    }
  }
  return jsonNode;
}

代码示例来源:origin: liferay/liferay-portal

private static JsonNode _findJsonNode(JsonNode resource, String nodeName) {
  JsonNode jsonNode = resource.path(nodeName);
  if (_log.isDebugEnabled()) {
    if (jsonNode.isMissingNode()) {
      _log.debug("Unable to find the \"{}\" node", nodeName);
    }
    if (jsonNode.isArray() && (jsonNode.size() == 0)) {
      _log.debug("The \"{}\" array node is empty", jsonNode);
    }
  }
  return jsonNode;
}

代码示例来源:origin: testcontainers/testcontainers-java

private AuthConfig authConfigUsingStore(final JsonNode config, final String reposName) throws Exception {
  final JsonNode credsStoreNode = config.get("credsStore");
  if (credsStoreNode != null && !credsStoreNode.isMissingNode() && credsStoreNode.isTextual()) {
    final String credsStore = credsStoreNode.asText();
    return runCredentialProvider(reposName, credsStore);
  }
  return null;
}

代码示例来源:origin: liferay/liferay-portal

private void _validateSingleModel() throws IOException {
  JsonNode contextJsonNode = getContextJsonNode();
  if (contextJsonNode.isMissingNode()) {
    throw new IOException(
      "The given resource does not have context node");
  }
}

代码示例来源:origin: opentripplanner/OpenTripPlanner

private JsonNode getJsonNode(String rentalString, String jsonParsePath) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    JsonNode rootNode = mapper.readTree(rentalString);
    if (!jsonParsePath.equals("")) {
        String delimiter = "/";
        String[] parseElement = jsonParsePath.split(delimiter);
        for (int i = 0; i < parseElement.length; i++) {
            rootNode = rootNode.path(parseElement[i]);
        }
        if (rootNode.isMissingNode()) {
            throw new IllegalArgumentException(
                "Could not find jSON elements " + jsonParsePath);
        }
    }
    return rootNode;
}

代码示例来源:origin: Graylog2/graylog2-server

public Optional<IndexStatistics> getIndexStats(String index) {
  final JsonNode indexStats = indexStatsWithShardLevel(index);
  return indexStats.isMissingNode() ? Optional.empty() : Optional.of(buildIndexStatistics(index, indexStats));
}

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

@Override
  public JsonNode digest(final JsonNode schema)
  {
    final ObjectNode ret = FACTORY.objectNode();
    ret.put("itemsSize", 0);
    ret.put("itemsIsArray", false);

    final JsonNode itemsNode = schema.path("items");
    final JsonNode additionalNode = schema.path("additionalItems");

    final boolean hasItems = !itemsNode.isMissingNode();
    final boolean hasAdditional = additionalNode.isObject();

    ret.put("hasItems", hasItems);
    ret.put("hasAdditional", hasAdditional);

    if (itemsNode.isArray()) {
      ret.put("itemsIsArray", true);
      ret.put("itemsSize", itemsNode.size());
    }

    return ret;
  }
}

代码示例来源:origin: opentripplanner/OpenTripPlanner

/** Create a BucketConfig from a JSON configuration node. */
public static S3BucketConfig fromConfig(JsonNode config) {
  if (config == null || config.isMissingNode()) {
    /* No configuration was specified, nothing should be downloaded from S3. */
    return null;
  }
  S3BucketConfig bucketConfig = new S3BucketConfig();
  try {
    bucketConfig.accessKey = config.get("accessKey").asText();
    bucketConfig.secretKey = config.get("secretKey").asText();
    bucketConfig.bucketName = config.get("bucketName").asText();
  } catch (NullPointerException ex) {
    LOG.error("You must specify an accessKey, a secretKey, and a bucketName when configuring S3 download.");
    throw ex;
  }
  return bucketConfig;
}

代码示例来源:origin: auth0/java-jwt

/**
 * Helper method to create a Claim representation from the given JsonNode.
 *
 * @param node the JsonNode to convert into a Claim.
 * @return a valid Claim instance. If the node is null or missing, a NullClaim will be returned.
 */
static Claim claimFromNode(JsonNode node, ObjectReader objectReader) {
  if (node == null || node.isNull() || node.isMissingNode()) {
    return new NullClaim();
  }
  return new JsonNodeClaim(node, objectReader);
}

代码示例来源:origin: liferay/liferay-portal

/**
 * Parses the given jsonNode (Resource Collection) e.g people, blog-postings
 * and returns the name of the resource element fields based on the first
 * entry
 *
 * @return <code>List<String></code> Name of the resource fields, empty
 *         collection otherwise
 * @review
 */
public List<String> getResourceElementFieldNames() {
  JsonNode firstEntryJsonNode = getFirstEntryJsonNode();
  if (firstEntryJsonNode.isMissingNode() || firstEntryJsonNode.isNull()) {
    return Collections.emptyList();
  }
  List<String> fieldNames = new ArrayList<>();
  Iterator<String> iterator = firstEntryJsonNode.fieldNames();
  while (iterator.hasNext()) {
    fieldNames.add(iterator.next());
  }
  return fieldNames;
}

代码示例来源:origin: Graylog2/graylog2-server

if (hostNode.isMissingNode()) {
  log.warn(prefix + "is missing mandatory \"host\" field.");
} else {
if (!shortMessageNode.isMissingNode()) {
  if (!shortMessageNode.isTextual()) {
    throw new IllegalArgumentException(prefix + "has invalid \"short_message\": " + shortMessageNode.asText());
    throw new IllegalArgumentException(prefix + "has empty mandatory \"short_message\" field.");
} else if (!messageNode.isMissingNode()) {
  if (!messageNode.isTextual()) {
    throw new IllegalArgumentException(prefix + "has invalid \"message\": " + messageNode.asText());

代码示例来源: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: Graylog2/graylog2-server

private Set<String> getReopenedIndices(final Collection<String> indices) {
  final Version elasticsearchVersion = node.getVersion().orElseThrow(() -> new ElasticsearchException("Unable to retrieve Elasticsearch version."));
  final String indexList = String.join(",", indices);
  final State request = new State.Builder().withMetadata().indices(indexList).build();
  final JestResult jestResult = JestUtils.execute(jestClient, request, () -> "Couldn't read cluster state for reopened indices " + indices);
  final JsonNode clusterStateJson = jestResult.getJsonObject();
  final JsonNode indicesJson = clusterStateJson.path("metadata").path("indices");
  final ImmutableSet.Builder<String> reopenedIndices = ImmutableSet.builder();
  if (indicesJson.isMissingNode()) {
    LOG.error("Retrieved cluster state is invalid (no metadata.indices key).");
    LOG.debug("Received cluster state was: {}", clusterStateJson.toString());
    return Collections.emptySet();
  }
  for (Iterator<Map.Entry<String, JsonNode>> it = indicesJson.fields(); it.hasNext(); ) {
    final Map.Entry<String, JsonNode> entry = it.next();
    final String indexName = entry.getKey();
    final JsonNode value = entry.getValue();
    final JsonNode indexSettings = value.path("settings");
    if (indexSettings.isMissingNode()) {
      LOG.error("Unable to retrieve index settings from metadata for index {} - skipping.", indexName);
      LOG.debug("Index metadata was: {}", value.toString());
      continue;
    }
    if (checkForReopened(indexSettings, elasticsearchVersion)) {
      LOG.debug("Adding {} to list of indices to be migrated.", indexName);
      reopenedIndices.add(indexName);
    }
  }
  return reopenedIndices.build();
}

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

@Override
 public Object apply(JsonNode node)
 {
  if (node == null || node.isMissingNode() || node.isNull()) {
   return null;
  }
  if (node.isIntegralNumber()) {
   if (node.canConvertToLong()) {
    return node.asLong();
   } else {
    return node.asDouble();
   }
  }
  if (node.isFloatingPointNumber()) {
   return node.asDouble();
  }
  final String s = node.asText();
  final CharsetEncoder enc = StandardCharsets.UTF_8.newEncoder();
  if (s != null && !enc.canEncode(s)) {
   // Some whacky characters are in this string (e.g. \uD900). These are problematic because they are decodeable
   // by new String(...) but will not encode into the same character. This dance here will replace these
   // characters with something more sane.
   return StringUtils.fromUtf8(StringUtils.toUtf8(s));
  } else {
   return s;
  }
 }
};

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

/**
 * Build a {@link JsonSchema} instance
 *
 * @param schema the schema
 * @param pointer the pointer into the schema
 * @return a new {@link JsonSchema}
 * @throws ProcessingException resolving the pointer against the schema
 * leads to a {@link MissingNode}
 * @throws NullPointerException the schema or pointer is null
 */
JsonSchema buildJsonSchema(final JsonNode schema, final JsonPointer pointer)
  throws ProcessingException
{
  final SchemaTree tree = loader.load(schema).setPointer(pointer);
  if (tree.getNode().isMissingNode())
    throw new JsonReferenceException(new ProcessingMessage()
      .setMessage(BUNDLE.getMessage("danglingRef")));
  return new JsonSchemaImpl(processor, tree, reportProvider);
}

相关文章