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

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

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

JsonNode.isIntegralNumber介绍

暂无

代码示例

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

@Nullable
private Object valueNode(JsonNode jsonNode) {
  if (jsonNode.isInt()) {
    return jsonNode.asInt();
  } else if (jsonNode.isLong()) {
    return jsonNode.asLong();
  } else if (jsonNode.isIntegralNumber()) {
    return jsonNode.asLong();
  } else if (jsonNode.isFloatingPointNumber()) {
    return jsonNode.asDouble();
  } else if (jsonNode.isBoolean()) {
    return jsonNode.asBoolean();
  } else if (jsonNode.isNull()) {
    return null;
  } else {
    return jsonNode.asText();
  }
}

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

private byte[] extractJNodeValue(final JsonNode n){
  if (n.isBoolean()){
    //boolean
    return clientService.toBytes(n.asBoolean());
  }else if(n.isNumber()){
    if(n.isIntegralNumber()){
      //interpret as Long
      return clientService.toBytes(n.asLong());
    }else{
      //interpret as Double
      return clientService.toBytes(n.asDouble());
    }
  }else{
    //if all else fails, interpret as String
    return clientService.toBytes(n.asText());
  }
}

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

} else if (value.isFloatingPointNumber()) {
  fieldValue = value.asDouble();
} else if (value.isIntegralNumber()) {
  fieldValue = value.asLong();
} else if (value.isNull()) {

代码示例来源:origin: briandilley/jsonrpc4j

private Object parseId(JsonNode node) {
  if (isNullNodeOrValue(node)) {
    return null;
  }
  if (node.isDouble()) {
    return node.asDouble();
  }
  if (node.isFloatingPointNumber()) {
    return node.asDouble();
  }
  if (node.isInt()) {
    return node.asInt();
  }
  if (node.isLong()) {
    return node.asLong();
  }
  //TODO(donequis): consider parsing bigints
  if (node.isIntegralNumber()) {
    return node.asInt();
  }
  if (node.isTextual()) {
    return node.asText();
  }
  throw new IllegalArgumentException("Unknown id type");
}

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

eb.setAttribute(attr, mapper.convertValue(fn, attr.getJacksonType()));
} else {
  if (fn.isIntegralNumber()) {
    eb.setAttribute(TypedName.create(name, Long.class), fn.asLong());
  } else if (fn.isFloatingPointNumber()) {

代码示例来源:origin: briandilley/jsonrpc4j

@Test
public void idIntegerType() throws Exception {
  EasyMock.expect(mockService.testMethod(param1)).andReturn(param1);
  EasyMock.replay(mockService);
  jsonRpcServer.handleRequest(messageWithListParamsStream(intParam1, "testMethod", param1), byteArrayOutputStream);
  assertTrue(decodeAnswer(byteArrayOutputStream).get(ID).isIntegralNumber());
}

代码示例来源:origin: briandilley/jsonrpc4j

private void checkSuccessfulResponse(MockHttpServletResponse response) throws IOException {
  assertTrue(HttpServletResponse.SC_OK == response.getStatus());
  JsonNode responseEnvelope = decodeAnswer(toByteArrayOutputStream(response.getContentAsByteArray()));
  assertTrue(responseEnvelope.get(ID).isIntegralNumber());
  assertEquals(responseEnvelope.get(ID).asLong(), 123L);
  assertTrue(responseEnvelope.get(RESULT).isTextual());
  assertEquals(responseEnvelope.get(RESULT).asText(), "For?est");
}

代码示例来源:origin: io.github.moacchain/core

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: line/centraldogma

private static boolean numEquals(final JsonNode a, final JsonNode b) {
  /*
   * If both numbers are integers, delegate to JsonNode.
   */
  if (a.isIntegralNumber() && b.isIntegralNumber()) {
    return a.equals(b);
  }
  /*
   * Otherwise, compare decimal values.
   */
  return a.decimalValue().compareTo(b.decimalValue()) == 0;
}

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common

private static boolean numEquals(final JsonNode a, final JsonNode b) {
  /*
   * If both numbers are integers, delegate to JsonNode.
   */
  if (a.isIntegralNumber() && b.isIntegralNumber()) {
    return a.equals(b);
  }
  /*
   * Otherwise, compare decimal values.
   */
  return a.decimalValue().compareTo(b.decimalValue()) == 0;
}

代码示例来源:origin: com.github.java-json-tools/jackson-coreutils

private static boolean numEquals(final JsonNode a, final JsonNode b)
{
  /*
   * If both numbers are integers, delegate to JsonNode.
   */
  if (a.isIntegralNumber() && b.isIntegralNumber())
    return a.equals(b);
  /*
   * Otherwise, compare decimal values.
   */
  return a.decimalValue().compareTo(b.decimalValue()) == 0;
}

代码示例来源:origin: com.networknt/json-schema-validator

public MinLengthValidator(String schemaPath, JsonNode schemaNode, JsonSchema parentSchema, ValidationContext validationContext) {
  super(schemaPath, schemaNode, parentSchema, ValidatorTypeCode.MIN_LENGTH, validationContext);
  minLength = Integer.MIN_VALUE;
  if (schemaNode != null && schemaNode.isIntegralNumber()) {
    minLength = schemaNode.intValue();
  }
  parseErrorCode(getValidatorType().getErrorCodeKey());
}

代码示例来源:origin: com.networknt/json-schema-validator

public MinPropertiesValidator(String schemaPath, JsonNode schemaNode, JsonSchema parentSchema,
    ValidationContext validationContext) {
  super(schemaPath, schemaNode, parentSchema, ValidatorTypeCode.MIN_PROPERTIES, validationContext);
  if (schemaNode.isIntegralNumber()) {
    min = schemaNode.intValue();
  }
  parseErrorCode(getValidatorType().getErrorCodeKey());
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

/**
 * Extracts long value from JsonNode if it is within bounds.
 *
 * <p>Throws {@link UnsupportedRowJsonException} if value is out of bounds.
 */
static ValueExtractor<Long> longValueExtractor() {
 return ValidatingValueExtractor.<Long>builder()
   .setExtractor(JsonNode::longValue)
   .setValidator(jsonNode -> jsonNode.isIntegralNumber() && jsonNode.canConvertToLong())
   .build();
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

/**
 * Extracts int value from JsonNode if it is within bounds.
 *
 * <p>Throws {@link UnsupportedRowJsonException} if value is out of bounds.
 */
static ValueExtractor<Integer> intValueExtractor() {
 return ValidatingValueExtractor.<Integer>builder()
   .setExtractor(JsonNode::intValue)
   .setValidator(jsonNode -> jsonNode.isIntegralNumber() && jsonNode.canConvertToInt())
   .build();
}

相关文章