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

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

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

JsonNode.isTextual介绍

[英]Method that checks whether this node represents basic JSON String value.
[中]方法,该方法检查此节点是否表示基本JSON字符串值。

代码示例

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

@Override
public String asString() {
  return !data.isTextual() ? null : data.asText();
}

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

@Override
public String getString(int rowIndex, int columnIndex) {
 JsonNode jsonValue = _resultsArray.get(rowIndex).get(columnIndex);
 if (jsonValue.isTextual()) {
  return jsonValue.textValue();
 } else {
  return jsonValue.toString();
 }
}

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

/**
 * Get a textual value from a json object, throwing an exception if the node is missing or not textual.
 */
private String getText(JsonNode jsonObject, String nodeName) {
  JsonNode subNode = jsonObject.get(nodeName);
  if (subNode == null) {
    return null;
  }
  if (!subNode.isTextual()) {
    throw new IllegalStateException(nodeName + " from credential process should be textual, but was " +
                    subNode.getNodeType());
  }
  return subNode.asText();
}

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

private String getTypeName(JsonNode node) {
  if (node.has("type") && node.get("type").isArray() && node.get("type").size() > 0) {
    for (JsonNode jsonNode : node.get("type")) {
      String typeName = jsonNode.asText();
      if (!typeName.equals("null")) {
        return typeName;
      }
    }
  }
  if (node.has("type") && node.get("type").isTextual()) {
    return node.get("type").asText();
  }
  return DEFAULT_TYPE_NAME;
}

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

private static void addHeader(DeserializationContext ctx, HttpHeaders headers,
                 AsciiString name, JsonNode valueNode) throws JsonMappingException {
    if (!valueNode.isTextual()) {
      ctx.reportInputMismatch(HttpHeaders.class,
                  "HTTP header '%s' contains %s (%s); only strings are allowed.",
                  name, valueNode.getNodeType(), valueNode);
    }

    headers.add(name, valueNode.asText());
  }
}

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

private AuthConfig authConfigUsingHelper(final JsonNode config, final String reposName) throws Exception {
  final JsonNode credHelpers = config.get("credHelpers");
  if (credHelpers != null && credHelpers.size() > 0) {
    final JsonNode helperNode = credHelpers.get(reposName);
    if (helperNode != null && helperNode.isTextual()) {
      final String helper = helperNode.asText();
      return runCredentialProvider(reposName, helper);
    }
  }
  return null;
}

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

public static JsonNode validateIfNodeIsTextual(JsonNode node) {
 if (node != null && !node.isNull() && node.isTextual() && StringUtils.isNotEmpty(node.asText())) {
  try {
   node = validateIfNodeIsTextual(objectMapper.readTree(node.asText()));
  } catch(Exception e) {
   logger.error("Error converting textual node", e);
  }
 }
 return node;
}

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

@Override
 public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
   throws IOException {

  ObjectCodec oc = jsonParser.getCodec();
  JsonNode node = oc.readTree(jsonParser);
  if (node.isTextual()) {
   return node.textValue();
  } else if (node.isObject()) {
   JsonNode allNode = node.get("__all__");
   if (allNode != null && allNode.isArray()) {
    StringBuilder buf = new StringBuilder();
    for (JsonNode msgNode : allNode) {
     buf.append(msgNode.textValue());
     buf.append(",");
    }

    return buf.length() > 0 ? buf.substring(0, buf.length() - 1) : buf.toString();
   }

   return node.toString();
  }

  return null;
 }
}

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

@Override
  public PathDetail deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonNode pathDetail = jp.readValueAsTree();
    if (pathDetail.size() != 3)
      throw new JsonParseException(jp, "PathDetail array must have exactly 3 entries but was " + pathDetail.size());

    JsonNode from = pathDetail.get(0);
    JsonNode to = pathDetail.get(1);
    JsonNode val = pathDetail.get(2);

    PathDetail pd;
    if (val.isBoolean())
      pd = new PathDetail(val.asBoolean());
    else if (val.isLong())
      pd = new PathDetail(val.asLong());
    else if (val.isInt())
      pd = new PathDetail(val.asInt());
    else if (val.isDouble())
      pd = new PathDetail(val.asDouble());
    else if (val.isTextual())
      pd = new PathDetail(val.asText());
    else
      throw new JsonParseException(jp, "Unsupported type of PathDetail value " + pathDetail.getNodeType().name());

    pd.setFirst(from.asInt());
    pd.setLast(to.asInt());
    return pd;
  }
}

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

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

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

List<String> getStringOrArray(Map<String, JsonNode> tree, String claimName) throws JWTDecodeException {
  JsonNode node = tree.get(claimName);
  if (node == null || node.isNull() || !(node.isArray() || node.isTextual())) {
    return null;
  }
  if (node.isTextual() && !node.asText().isEmpty()) {
    return Collections.singletonList(node.asText());
  }
  List<String> list = new ArrayList<>(node.size());
  for (int i = 0; i < node.size(); i++) {
    try {
      list.add(objectReader.treeToValue(node.get(i), String.class));
    } catch (JsonProcessingException e) {
      throw new JWTDecodeException("Couldn't map the Claim's array contents to String", e);
    }
  }
  return list;
}

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

private static double timestampValue(final JsonNode json) {
  final JsonNode value = json.path(Message.FIELD_TIMESTAMP);
  if (value.isNumber()) {
    return value.asDouble(-1.0);
  } else if (value.isTextual()) {
    try {
      return Double.parseDouble(value.asText());
    } catch (NumberFormatException e) {
      log.debug("Unable to parse timestamp", e);
      return -1.0;
    }
  } else {
    return -1.0;
  }
}

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

@Override
 public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
   throws IOException {

  ObjectCodec oc = jsonParser.getCodec();
  JsonNode node = oc.readTree(jsonParser);
  if (node.isTextual()) {
   return node.textValue();
  } else if (node.isObject()) {
   JsonNode allNode = node.get("__all__");
   if (allNode != null && allNode.isArray()) {
    StringBuilder buf = new StringBuilder();
    for (JsonNode msgNode : allNode) {
     buf.append(msgNode.textValue());
     buf.append(",");
    }

    return buf.length() > 0 ? buf.substring(0, buf.length() - 1) : buf.toString();
   }

   return node.toString();
  }

  return null;
 }
}

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

/**
 * Get a textual value from a json object, throwing an exception if the node is missing or not textual.
 */
private String getText(JsonNode jsonObject, String nodeName) {
  JsonNode subNode = jsonObject.get(nodeName);
  if (subNode == null) {
    return null;
  }
  if (!subNode.isTextual()) {
    throw new IllegalStateException(nodeName + " from credential process should be textual, but was " +
                    subNode.getNodeType());
  }
  return subNode.asText();
}

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

/**
 * Parse the error message from the response.
 *
 * @return Error Code of exceptional response or null if it can't be determined
 */
public String parseErrorMessage(HttpResponse httpResponse, JsonNode jsonNode) {
  // If X_AMZN_ERROR_MESSAGE is present, prefer that. Otherwise check the JSON body.
  final String headerMessage = httpResponse.getHeader(X_AMZN_ERROR_MESSAGE);
  if (headerMessage != null) {
    return headerMessage;
  }
  for (String field : errorMessageJsonLocations) {
    JsonNode value = jsonNode.get(field);
    if (value != null && value.isTextual()) {
      return value.asText();
    }
  }
  return null;
}

代码示例来源:origin: rampatra/jbot

@JsonSetter("channel")
public void setChannel(JsonNode jsonNode) {
  if (jsonNode.isObject()) {
    try {
      this.channel = new ObjectMapper().treeToValue(jsonNode, Channel.class);
    } catch (JsonProcessingException e) {
      logger.error("Error deserializing json: ", e);
    }
  } else if (jsonNode.isTextual()) {
    this.channelId = jsonNode.asText();
  }
}

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

@Override
 public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
   throws IOException, JsonProcessingException {

  ObjectCodec oc = jsonParser.getCodec();
  JsonNode node = oc.readTree(jsonParser);
  if (node.isTextual()) {
   return node.textValue();
  } else if (node.isObject()) {
   JsonNode allNode = node.get("__all__");
   if (allNode != null && allNode.isArray()) {
    StringBuffer buf = new StringBuffer();
    for (JsonNode msgNode : allNode) {
     buf.append(msgNode.textValue());
     buf.append(",");
    }

    return buf.length() > 0 ? buf.substring(0, buf.length() - 1) : buf.toString();
   }

   return node.toString();
  }

  return null;
 }
}

代码示例来源: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: rampatra/jbot

@JsonSetter("file")
public void setFile(JsonNode jsonNode) {
  if (jsonNode.isObject()) {
    try {
      this.file = new ObjectMapper().treeToValue(jsonNode, File.class);
    } catch (JsonProcessingException e) {
      logger.error("Error deserializing json: ", e);
    }
  } else if (jsonNode.isTextual()) {
    this.fileId = jsonNode.asText();
  }
}

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

@Override
 public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
   throws IOException, JsonProcessingException {

  ObjectCodec oc = jsonParser.getCodec();
  JsonNode node = oc.readTree(jsonParser);
  if (node.isTextual()) {
   return node.textValue();
  } else if (node.isObject()) {
   JsonNode allNode = node.get("__all__");
   if (allNode != null && allNode.isArray()) {
    StringBuffer buf = new StringBuffer();
    for (JsonNode msgNode : allNode) {
     buf.append(msgNode.textValue());
     buf.append(",");
    }

    return buf.length() > 0 ? buf.substring(0, buf.length() - 1) : buf.toString();
   }

   return node.toString();
  }

  return null;
 }
}

相关文章