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

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

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

JsonNode.isValueNode介绍

[英]Method that returns true for all value nodes: ones that are not containers, and that do not represent "missing" nodes in the path. Such value nodes represent String, Number, Boolean and null values from JSON.

Note: one and only one of methods #isValueNode, #isContainerNode and #isMissingNode ever returns true for any given node.
[中]方法,该方法为所有值节点返回true:这些节点不是容器,并且不表示路径中的“缺失”节点。这些值节点表示JSON中的字符串、数字、布尔值和空值。
注意:对于任何给定节点,方法#isValueNode、#isContainerNode和#isMissingNode中只有一个会返回true。

代码示例

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

private static Object extractSingleValue(JsonNode jsonValue, FieldSpec.DataType dataType) {
  Preconditions.checkArgument(jsonValue.isValueNode());
  switch (dataType) {
   case INT:
    return jsonValue.asInt();
   case LONG:
    return jsonValue.asLong();
   case FLOAT:
    return (float) jsonValue.asDouble();
   case DOUBLE:
    return jsonValue.asDouble();
   case STRING:
    return jsonValue.asText();
   default:
    throw new IllegalArgumentException();
  }
 }
}

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

@Override
public boolean getBoolean()
{
  if (value.isValueNode()) {
    return value.asBoolean();
  }
  throw new PrestoException(
      DECODER_CONVERSION_NOT_SUPPORTED,
      format("could not parse non-value node as '%s' for column '%s'", columnHandle.getType(), columnHandle.getName()));
}

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

public static boolean hasValueOf(String value, JsonNode jsonNode) {
  if (jsonNode.isArray()) {
    Iterator<JsonNode> iterator = jsonNode.elements();
    while (iterator.hasNext()) {
      JsonNode entryJsonNode = iterator.next();
      String entry = entryJsonNode.asText();
      if (entry.equals(value)) {
        return true;
      }
    }
  }
  else if (jsonNode.isValueNode()) {
    String entry = jsonNode.asText();
    if (entry.equals(value)) {
      return true;
    }
  }
  return false;
}

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

@Deprecated
public ToString(com.google.common.base.Optional<JsonNode> option) throws JsonMappingException {
  JsonNode node = option.or(NullNode.getInstance());
  if (node.isTextual()) {
    this.string = node.textValue();
  } else if (node.isValueNode()) {
    this.string = node.toString();
  } else {
    throw new JsonMappingException(String.format("Arrays and objects are invalid: '%s'", node));
  }
}

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

@JsonCreator
public ToString(final Optional<JsonNode> option) throws JsonMappingException {
  final JsonNode node = option.orElse(NullNode.getInstance());
  if (node.isTextual()) {
    this.string = node.textValue();
  } else if (node.isValueNode()) {
    this.string = node.toString();
  } else {
    throw new JsonMappingException(String.format("Arrays and objects are invalid: '%s'", node));
  }
}

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

private void addFlattened(Message message, String currentPath, JsonNode jsonNode) {
  if (jsonNode.isObject()) {
    final Iterator<Map.Entry<String, JsonNode>> it = jsonNode.fields();
    final String pathPrefix = currentPath.isEmpty() ? "" : currentPath + MAP_KEY_SEPARATOR;
    while (it.hasNext()) {
      final Map.Entry<String, JsonNode> entry = it.next();
      addFlattened(message, pathPrefix + entry.getKey(), entry.getValue());
    }
  } else if (jsonNode.isArray()) {
    final List<Object> values = new ArrayList<>(jsonNode.size());
    for (int i = 0; i < jsonNode.size(); i++) {
      final JsonNode currentNode = jsonNode.get(i);
      if (currentNode.isObject()) {
        final String pathPrefix = currentPath.isEmpty() ? "" : currentPath + MAP_KEY_SEPARATOR + i;
        addFlattened(message, pathPrefix, currentNode);
      } else if (currentNode.isValueNode()) {
        values.add(valueNode(currentNode));
      }
    }
    message.addField(currentPath, values);
  } else if (jsonNode.isValueNode()) {
    message.addField(currentPath, valueNode(jsonNode));
  }
}

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

@Override
  public Slice getSlice()
  {
    String textValue = value.isValueNode() ? value.asText() : value.toString();
    Slice slice = utf8Slice(textValue);
    if (isVarcharType(columnHandle.getType())) {
      slice = truncateToLength(slice, columnHandle.getType());
    }
    return slice;
  }
}

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

@Override
public double getDouble()
{
  try {
    if (value.isNumber()) {
      return value.doubleValue();
    }
    if (value.isValueNode()) {
      return parseDouble(value.asText());
    }
  }
  catch (NumberFormatException ignore) {
    // ignore
  }
  throw new PrestoException(
      DECODER_CONVERSION_NOT_SUPPORTED,
      format("could not parse value '%s' as '%s' for column '%s'", value.asText(), columnHandle.getType(), columnHandle.getName()));
}

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

if (timestampNode.isValueNode() && !timestampNode.isNumber()) {
  log.warn(prefix + "has invalid \"timestamp\": {}  (type: {})", timestampNode.asText(), timestampNode.getNodeType().name());

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

.collect(Collectors.joining("."));
if (obj.has(remainingPath) && !remainingPath.equals(key)) {
  if (obj.get(remainingPath).isValueNode()) {
    obj.put(remainingPath, value);
    return;

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

@Override
  protected long getMillis()
  {
    if (value.isValueNode()) {
      try {
        return FORMATTER.parseMillis(value.asText());
      }
      catch (IllegalArgumentException e) {
        throw new PrestoException(
            DECODER_CONVERSION_NOT_SUPPORTED,
            format("could not parse value '%s' as '%s' for column '%s'", value.asText(), columnHandle.getType(), columnHandle.getName()));
      }
    }
    throw new PrestoException(
        DECODER_CONVERSION_NOT_SUPPORTED,
        format("could not parse non-value node as '%s' for column '%s'", columnHandle.getType(), columnHandle.getName()));
  }
}

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

@Override
  protected long getMillis()
  {
    if (!value.isValueNode()) {
      throw new PrestoException(
          DECODER_CONVERSION_NOT_SUPPORTED,
          format("could not parse non-value node as '%s' for column '%s'", columnHandle.getType(), columnHandle.getName()));
    }
    try {
      return formatter.parseMillis(value.asText());
    }
    catch (IllegalArgumentException e) {
      throw new PrestoException(
          DECODER_CONVERSION_NOT_SUPPORTED,
          format("could not parse value '%s' as '%s' for column '%s'", value.asText(), columnHandle.getType(), columnHandle.getName()));
    }
  }
}

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

@Override
public long getLong()
{
  try {
    long longValue;
    if (value.isIntegralNumber() && !value.isBigInteger()) {
      longValue = value.longValue();
      if (longValue >= minValue && longValue <= maxValue) {
        return longValue;
      }
    }
    else if (value.isValueNode()) {
      longValue = parseLong(value.asText());
      if (longValue >= minValue && longValue <= maxValue) {
        return longValue;
      }
    }
  }
  catch (NumberFormatException ignore) {
    // ignore
  }
  throw new PrestoException(
      DECODER_CONVERSION_NOT_SUPPORTED,
      format("could not parse value '%s' as '%s' for column '%s'", value.asText(), columnHandle.getType(), columnHandle.getName()));
}

代码示例来源:origin: spullara/mustache.java

private Object convert(final JsonNode value) {
  if (value == null || value.isNull()) return null;
  if (value.isBoolean()) {
   return value.booleanValue();
  } else if (value.isValueNode()) {
   return value.asText();
  } else if (value.isArray()) {
   return (Iterable) () -> new Iterator() {
    private Iterator<JsonNode> iterator = value.iterator();
    @Override
    public boolean hasNext() {
     return iterator.hasNext();
    }
    @Override
    public Object next() {
     return convert(iterator.next());
    }
    @Override
    public void remove() {
    }
   };
  } else {
   return new JsonMap(value);
  }
 }
}

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

if (objectNode.isValueNode() && StringUtils.isNotEmpty(objectNode.asText())) {
 try {
  objectNode = objectMapper.readTree(objectNode.asText());

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

@Override
  protected long getMillis()
  {
    if (value.isIntegralNumber() && !value.isBigInteger()) {
      return value.longValue();
    }
    if (value.isValueNode()) {
      try {
        return parseLong(value.asText());
      }
      catch (NumberFormatException e) {
        throw new PrestoException(
            DECODER_CONVERSION_NOT_SUPPORTED,
            format("could not parse value '%s' as '%s' for column '%s'", value.asText(), columnHandle.getType(), columnHandle.getName()));
      }
    }
    throw new PrestoException(
        DECODER_CONVERSION_NOT_SUPPORTED,
        format("could not parse non-value node as '%s' for column '%s'", columnHandle.getType(), columnHandle.getName()));
  }
}

代码示例来源:origin: zendesk/maxwell

private void readDataInto(RowMap dest, JsonNode data, boolean isOld) throws IOException {
  if (!(data instanceof ObjectNode)) {
    throw new ParseException("`" + (isOld ? "oldData" : "data") + "` cannot be parsed.");
  }
  Iterator keys = data.fieldNames();
  if (keys != null) {
    while (keys.hasNext()) {
      String key = (String) keys.next();
      JsonNode value = data.get(key);
      if (value.isValueNode()) {
        ValueNode valueNode = (ValueNode) value;
        if(isOld) {
          dest.putOldData(key, getValue(valueNode));
        } else {
          dest.putData(key, getValue(valueNode));
        }
      }
    }
  }
}

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

@Override
  protected long getMillis()
  {
    try {
      if (value.isIntegralNumber()
          && !value.isBigInteger()) {
        return multiplyExact(value.longValue(), 1000);
      }
      if (value.isValueNode()) {
        return multiplyExact(parseLong(value.asText()), 1000);
      }
      throw new PrestoException(
          DECODER_CONVERSION_NOT_SUPPORTED,
          format("could not parse non-value node as '%s' for column '%s'", columnHandle.getType(), columnHandle.getName()));
    }
    catch (NumberFormatException | ArithmeticException e) {
      throw new PrestoException(
          DECODER_CONVERSION_NOT_SUPPORTED,
          format("could not parse value '%s' as '%s' for column '%s'", value.asText(), columnHandle.getType(), columnHandle.getName()));
    }
  }
}

代码示例来源:origin: json-path/JsonPath

if (e.isValueNode()) {

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

if (!value.isValueNode()) {
  throw new PrestoException(
      DECODER_CONVERSION_NOT_SUPPORTED,

相关文章