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

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

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

JsonNode.findValue介绍

[英]Method for finding a JSON Object field with specified name in this node or its child nodes, and returning value it has. If no matching field is found in this node or its descendants, returns null.
[中]方法,用于在此节点或其子节点中查找具有指定名称的JSON对象字段,并返回其具有的值。如果在此节点或其子节点中未找到匹配字段,则返回null。

代码示例

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

@Override
public JsonNode findValue(String fieldName)
{
  for (JsonNode node : _children) {
    JsonNode value = node.findValue(fieldName);
    if (value != null) {
      return value;
    }
  }
  return null;
}

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

@Override
public String translate(String text, String sourceLanguage,
            String targetLanguage) throws TikaException, IOException {
  if (!this.isAvailable)
    return text;
  Response response = client.accept(MediaType.APPLICATION_JSON)
      .query("user_key", userKey).query("source", sourceLanguage)
      .query("target", targetLanguage).query("q", text).get();
  BufferedReader reader = new BufferedReader(new InputStreamReader(
      (InputStream) response.getEntity(), UTF_8));
  String line = null;
  StringBuffer responseText = new StringBuffer();
  while ((line = reader.readLine()) != null) {
    responseText.append(line);
  }
  ObjectMapper mapper = new ObjectMapper();
  JsonNode jsonResp = mapper.readTree(responseText.toString());
  if (jsonResp.findValuesAsText("errors").isEmpty()) {
    return jsonResp.findValuesAsText("translation").get(0);
  } else {
    throw new TikaException(jsonResp.findValue("errors").get(0).asText());
  }
}

代码示例来源:origin: Netflix/conductor

private String getValue(String fieldName, JsonNode json) {
  JsonNode node = json.findValue(fieldName);
  if(node == null) {
    return null;
  }
  return node.textValue();
}

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

String code = jsonResp.findValuesAsText("code").get(0);
if (code.equals("200")) {
  return jsonResp.findValue("text").get(0).asText();
} else {
  throw new TikaException(jsonResp.findValue("message").get(0).asText());

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

@Override
public JsonNode findValue(String fieldName)
{
  for (Map.Entry<String, JsonNode> entry : _children.entrySet()) {
    if (fieldName.equals(entry.getKey())) {
      return entry.getValue();
    }
    JsonNode value = entry.getValue().findValue(fieldName);
    if (value != null) {
      return value;
    }
  }
  return null;
}

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

return jsonResp.findValuesAsText("outputText").get(0);
} else {
 throw new TikaException(jsonResp.findValue("message").get(0).asText());

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

public static Optional<AbsoluteRange> extractHistogramBoundaries(final String query) {
    try {
      final JsonParser jp = OBJECT_MAPPER.getFactory().createParser(query);
      final JsonNode rootNode = OBJECT_MAPPER.readTree(jp);
      final JsonNode timestampNode = rootNode.findValue("range").findValue("timestamp");
      final String from = elasticSearchTimeFormatToISO8601(timestampNode.findValue("from").asText());
      final String to = elasticSearchTimeFormatToISO8601(timestampNode.findValue("to").asText());

      return Optional.of(AbsoluteRange.create(from, to));
    } catch (Exception ignored) {
      return Optional.empty();
    }
  }
}

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

static String doGetEC2InstanceRegion(final String json) {
  if (null != json) {
    try {
      JsonNode node = mapper.readTree(json.getBytes(StringUtils.UTF8));
      JsonNode region = node.findValue(REGION);
      return region.asText();
    } catch (Exception e) {
      log.warn("Unable to parse EC2 instance info (" + json
          + ") : " + e.getMessage(), e);
    }
  }
  return null;
}

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

/**
   * Attempt to parse the error code from the response content. Returns null if information is not
   * present in the content. Codes are expected to be in the form <b>"typeName"</b> or
   * <b>"prefix#typeName"</b> Examples : "AccessDeniedException", "com.amazonaws.dynamodb.v20111205#ProvisionedThroughputExceededException"
   */
  private String parseErrorCodeFromContents(JsonNode jsonContents) {
    if (jsonContents == null || !jsonContents.has(errorCodeFieldName)) {
      return null;
    }
    String code = jsonContents.findValue(errorCodeFieldName).asText();
    int separator = code.lastIndexOf("#");
    return code.substring(separator + 1);
  }
}

代码示例来源:origin: spring-projects/spring-data-elasticsearch

private Map<String, Object> convertMappingResponse(String mappingResponse, String type) {
  ObjectMapper mapper = new ObjectMapper();
  try {
    Map result = null;
    JsonNode node = mapper.readTree(mappingResponse);
    node = node.findValue("mappings").findValue(type);
    result = mapper.readValue(mapper.writeValueAsString(node), HashMap.class);
    return result;
  } catch (IOException e) {
    throw new ElasticsearchException("Could not map alias response : " + mappingResponse, e);
  }
}

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

/**
 * Parses the given JsonNode which is a <code>@context</code> node and find
 * the value of the <code>@vocab</code> node.
 *
 * @param  contextJsonNode
 * @return <code>String</code> the Vocab's value e.g "@vocab":
 *         "http://schema.org" otherwise empty String
 * @review
 */
public String getVocabulary(JsonNode contextJsonNode) {
  JsonNode jsonNode = contextJsonNode.findValue(JSONLDConstants.VOCAB);
  if (jsonNode == null) {
    JsonNode missingNode = MissingNode.getInstance();
    return missingNode.asText();
  }
  return jsonNode.asText();
}

代码示例来源:origin: knowm/XChange

final long date = node.findValue("date").asLong();

代码示例来源:origin: spring-projects/spring-data-elasticsearch

/**
 * It takes two steps to create a List<AliasMetadata> from the elasticsearch http response because the aliases field
 * is actually a Map by alias name, but the alias name is on the AliasMetadata.
 * 
 * @param aliasResponse
 * @return
 */
List<AliasMetaData> convertAliasResponse(String aliasResponse) {
  ObjectMapper mapper = new ObjectMapper();
  try {
    JsonNode node = mapper.readTree(aliasResponse);
    Iterator<String> names = node.fieldNames();
    String name = names.next();
    node = node.findValue("aliases");
    Map<String, AliasData> aliasData = mapper.readValue(mapper.writeValueAsString(node),
        new TypeReference<Map<String, AliasData>>() {});
    Iterable<Map.Entry<String, AliasData>> aliasIter = aliasData.entrySet();
    List<AliasMetaData> aliasMetaDataList = new ArrayList<AliasMetaData>();
    for (Map.Entry<String, AliasData> aliasentry : aliasIter) {
      AliasData data = aliasentry.getValue();
      aliasMetaDataList.add(AliasMetaData.newAliasMetaDataBuilder(aliasentry.getKey()).filter(data.getFilter())
          .routing(data.getRouting()).searchRouting(data.getSearch_routing()).indexRouting(data.getIndex_routing())
          .build());
    }
    return aliasMetaDataList;
  } catch (IOException e) {
    throw new ElasticsearchException("Could not map alias response : " + aliasResponse, e);
  }
}

代码示例来源:origin: joelittlejohn/jsonschema2pojo

propertyNode = properties.findValue(requiredArrayItem);

代码示例来源:origin: com.amazonaws/aws-java-sdk-core

static String doGetEC2InstanceRegion(final String json) {
  if (null != json) {
    try {
      JsonNode node = mapper.readTree(json.getBytes(StringUtils.UTF8));
      JsonNode region = node.findValue(REGION);
      return region.asText();
    } catch (Exception e) {
      log.warn("Unable to parse EC2 instance info (" + json
          + ") : " + e.getMessage(), e);
    }
  }
  return null;
}

代码示例来源:origin: com.amazonaws/aws-java-sdk-core

/**
   * Attempt to parse the error code from the response content. Returns null if information is not
   * present in the content. Codes are expected to be in the form <b>"typeName"</b> or
   * <b>"prefix#typeName"</b> Examples : "AccessDeniedException", "com.amazonaws.dynamodb.v20111205#ProvisionedThroughputExceededException"
   */
  private String parseErrorCodeFromContents(JsonNode jsonContents) {
    if (jsonContents == null || !jsonContents.has(errorCodeFieldName)) {
      return null;
    }
    String code = jsonContents.findValue(errorCodeFieldName).asText();
    int separator = code.lastIndexOf("#");
    return code.substring(separator + 1);
  }
}

代码示例来源:origin: dearbinge/dubbo-spring-boot-mybatis-redis

public static JsonNode getJsonNodeByKey(String content, String key) throws JsonProcessingException, IOException {
    getObjectMapperInstance();
    mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false);// 序列化默认以类名为根元素
    JsonNode jsonNode = mapper.readTree(content);
    return jsonNode.findValue(key);
  }
}

代码示例来源:origin: com.jwebmp.jackson.core/jackson-databind

@Override
public JsonNode findValue(String fieldName)
{
  for (JsonNode node : _children) {
    JsonNode value = node.findValue(fieldName);
    if (value != null) {
      return value;
    }
  }
  return null;
}

代码示例来源:origin: com.eclipsesource.jaxrs/jersey-all

@Override
public JsonNode findValue(String fieldName)
{
  for (JsonNode node : _children) {
    JsonNode value = node.findValue(fieldName);
    if (value != null) {
      return value;
    }
  }
  return null;
}

代码示例来源:origin: datacleaner/DataCleaner

private Object[] getValues(final JsonNode readTree) {
  final List<Column> columns = getColumns();
  final Object[] list = new Object[columns.size()];
  for (int i = 0; i < columns.size(); i++) {
    final JsonNode node = readTree.findValue(columns.get(i).getName());
    final String value = node.asText();
    list[i] = value;
  }
  return list;
}

相关文章