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

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

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

JsonNode.longValue介绍

[英]Returns 64-bit long value for this node, if and only if this node is numeric ( #isNumber returns true). For other types returns 0. For floating-point numbers, value is truncated using default Java coercion, similar to how cast from double to long operates.
[中]返回此节点的64位长值,当且仅当此节点为数字时(#isNumber返回true)。对于其他类型,返回0。对于浮点数,使用默认Java强制截断值,类似于从double到long的转换操作。

代码示例

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

/**
 * Get a Long field from the JSON.
 *
 * @param json JSON document.
 * @param fieldName Field name to get.
 * @return Long value of field or null if not present.
 */
private Long getLongField(JsonNode json, String fieldName) {
  if (!json.has(fieldName)) {
    return null;
  }
  return json.get(fieldName).longValue();
}

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

@Override
public long getLongValue() throws IOException, JsonParseException {
  return currentNumericNode().longValue();
}

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

private long getReplyId(JsonNode replyJson) throws IOException {
  JsonNode idField = replyJson.get("id");
  if (idField == null) {
    throw new IOException("'id' field is missing in the reply");
  }
  if (!idField.isIntegralNumber()) {
    throw new IOException(
        String.format("'id' expected to be long, but it is: '%s'",
            idField.asText()));
  }
  return idField.longValue();
}

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

for (JsonNode node : tasks) {
  if (node.get("type").textValue().equals("MAP")) {
    if (node.get("elapsedTime").longValue() >= maxMapElapsedTime) {
      maxMapElapsedTime = node.get("elapsedTime").longValue();
      maxMapId = node.get("id").textValue();
    if (node.get("elapsedTime").longValue() <= minMapElapsedTime) {
      minMapElapsedTime = node.get("elapsedTime").longValue();
      minMapId = node.get("id").textValue();
    if (node.get("startTime").longValue() <= firstStartMapTime) {
      firstStartMapTime = node.get("startTime").longValue();
      firstStartMapId = node.get("id").textValue();
    if (node.get("startTime").longValue() >= lastStartMapTime) {
      lastStartMapTime = node.get("startTime").longValue();
      lastStartMapId = node.get("id").textValue();
    if (node.get("finishTime").longValue() <= firstEndMapTime) {
      firstEndMapTime = node.get("finishTime").longValue();
      firstEndMapId = node.get("id").textValue();
    if (node.get("finishTime").longValue() >= lastEndMapTime) {
      lastEndMapTime = node.get("finishTime").longValue();
      lastEndMapId = node.get("id").textValue();
    if (node.get("elapsedTime").longValue() >= maxReduceElapsedTime) {
      maxReduceElapsedTime = node.get("elapsedTime").longValue();
      maxReduceId = node.get("id").textValue();

代码示例来源: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: 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: java-json-tools/json-schema-validator

protected final ObjectNode digestedNumberNode(final JsonNode schema)
  {
    final ObjectNode ret = FACTORY.objectNode();

    final JsonNode node = schema.get(keyword);
    final boolean isLong = valueIsLong(node);
    ret.put("valueIsLong", isLong);

    if (isLong) {
      ret.put(keyword, node.canConvertToInt()
        ? FACTORY.numberNode(node.intValue())
        : FACTORY.numberNode(node.longValue()));
      return ret;
    }

    final BigDecimal decimal = node.decimalValue();
    ret.put(keyword, decimal.scale() == 0
      ? FACTORY.numberNode(decimal.toBigIntegerExact())
      : node);

    return ret;
  }
}

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

@Override
protected final void validateLong(final ProcessingReport report,
  final MessageBundle bundle, final FullData data)
  throws ProcessingException
{
  final JsonNode node = data.getInstance().getNode();
  final long instanceValue = node.longValue();
  final long longValue = number.longValue();
  final long remainder = instanceValue % longValue;
  if (remainder == 0L)
    return;
  report.error(newMsg(data, bundle, "err.common.divisor.nonZeroRemainder")
    .putArgument("value", node).putArgument("divisor", number));
}

代码示例来源: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: org.springframework.boot/spring-boot

return (D) Long.valueOf(jsonNode.longValue());

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

return ValueReference.of(value.longValue());
} else if (valueType == ValueType.STRING && value.isTextual()) {
  return ValueReference.of(value.textValue());

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

@Override
protected void validateLong(final ProcessingReport report,
  final MessageBundle bundle, final FullData data)
  throws ProcessingException
{
  final JsonNode instance = data.getInstance().getNode();
  final long instanceValue = instance.longValue();
  final long longValue = number.longValue();
  if (instanceValue > longValue)
    return;
  if (instanceValue < longValue) {
    report.error(newMsg(data, bundle, "err.common.minimum.tooSmall")
      .putArgument(keyword, number).putArgument("found", instance));
    return;
  }
  if (!exclusive)
    return;
  report.error(newMsg(data, bundle, "err.common.minimum.notExclusive")
    .putArgument(keyword, number)
    .put("exclusiveMinimum", BooleanNode.TRUE));
}

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

@Override
protected void validateLong(final ProcessingReport report,
  final MessageBundle bundle, final FullData data)
  throws ProcessingException
{
  final JsonNode instance = data.getInstance().getNode();
  final long instanceValue = instance.longValue();
  final long longValue = number.longValue();
  if (instanceValue < longValue)
    return;
  if (instanceValue > longValue) {
    report.error(newMsg(data, bundle, "err.common.maximum.tooLarge")
      .putArgument(keyword, number).putArgument("found", instance));
    return;
  }
  if (!exclusive)
    return;
  report.error(newMsg(data, bundle, "err.common.maximum.notExclusive")
    .putArgument(keyword, number)
    .put("exclusiveMaximum", BooleanNode.TRUE));
}

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

return new IntWritable(value.intValue());
case LONG:
 return (new LongWritable((value.longValue())));
case FLOAT:
 return (new FloatWritable(value.floatValue()));

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

if (!n.isNumber())
  throw new AvroTypeException("Non-numeric default value for long: "+n);
 e.writeLong(n.longValue());
 break;
case FLOAT:

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

case VALUE_NUMBER_INT:
 out.writeIndex(JsonType.LONG.ordinal());
 out.writeLong(node.longValue());
 break;
case VALUE_NUMBER_FLOAT:

代码示例来源:origin: com.ning/metrics.serialization-smile

public static DateTime getEventDateTimeFromJson(final JsonNode node)
{
  final JsonNode eventDateTimeNode = node.get(SMILE_EVENT_DATETIME_TOKEN_NAME);
  return (eventDateTimeNode == null) ?
      new DateTime() : new DateTime(eventDateTimeNode.longValue());
}

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

private Long getLongField(final JsonNode pNode, final String pFieldName) {
  Preconditions.checkNotNull(pNode);
  Preconditions.checkNotNull(pFieldName);
  return (pNode.get(pFieldName) != null && pNode.get(pFieldName).isLong()) ? pNode.get(pFieldName).longValue()
    : null;
}

代码示例来源:origin: com.jivesoftware.os.tasmo/tasmo-event-api

public long getEventId(ObjectNode eventNode) {
  JsonNode got = eventNode.get(ReservedFields.EVENT_ID);
  if (got == null || got.isNull()) {
    return 0L;
  }
  try {
    return got.longValue();
  } catch (Exception ex) {
    LOG.debug("Failed to get eventId: " + eventNode, ex);
    return 0L;
  }
}

代码示例来源:origin: com.jonnymatts/jzonbie-core

private Object convertJsonNodeToObject(JsonNode node) {
  if(node == null) return null;
  if(node instanceof NullNode) return null;
  if(node instanceof TextNode) return node.textValue();
  if(node instanceof IntNode) return node.intValue();
  if(node instanceof LongNode) return node.longValue();
  if(node instanceof BooleanNode) return node.booleanValue();
  if(node instanceof ArrayNode) return getListFromArrayNode((ArrayNode) node);
  if(node instanceof ObjectNode) return getMapFromObjectNode((ObjectNode) node);
  throw new RuntimeException("Unknown node type: " + node.getNodeType());
}

相关文章