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

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

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

JsonNode.isNumber介绍

暂无

代码示例

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

@Override
public Double asDouble() {
  return !data.isNumber() ? null : data.asDouble();
}

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

@Override
public Long asLong() {
  return !data.isNumber() ? null : data.asLong();
}

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

@Override
public Integer asInt() {
  return !data.isNumber() ? null : data.asInt();
}

代码示例来源: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: aws/aws-sdk-java

public BigDecimal getExpectedAsNumber() {
  if(expected.isNumber()) {
    return expected.decimalValue();
  }
  return null;
}

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

private Object extractBody(ClientResponse cr) {
  String json = cr.getEntity(String.class);
  logger.info(json);
  
  try {
    
    JsonNode node = om.readTree(json);
    if (node.isArray()) {
      return om.convertValue(node, listOfObj);
    } else if (node.isObject()) {
      return om.convertValue(node, mapOfObj);
    } else if (node.isNumber()) {
      return om.convertValue(node, Double.class);
    } else {
      return node.asText();
    }
  } catch (IOException jpe) {
    logger.error(jpe.getMessage(), jpe);
    return json;
  }
}

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

private long tookMsFromSearchResult(JestResult searchResult) {
  final JsonNode tookMs = searchResult.getJsonObject().path("took");
  if (tookMs.isNumber()) {
    return tookMs.asLong();
  } else {
    throw new ElasticsearchException("Unexpected response structure: " + searchResult.getJsonString());
  }
}

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

if (val.isNumber()) {
 return val.asDouble();

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

private Object toValue(JsonNode node)
      throws IOException
  {
    if (node.isTextual()) {
      return node.asText();
    }
    else if (node.isNumber()) {
      return node.numberValue();
    }
    else if (node.isBoolean()) {
      return node.asBoolean();
    }
    else if (node.isBinary()) {
      return node.binaryValue();
    }
    else {
      throw new IllegalStateException("Unexpected range bound value: " + node);
    }
  }
}

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

protected JsonNode currentNumericNode()
  throws JsonParseException
{
  JsonNode n = currentNode();
  if (n == null || !n.isNumber()) {
    JsonToken t = (n == null) ? null : n.asToken();
    throw _constructError("Current token ("+t+") not numeric, cannot use numeric value accessors");
  }
  return n;
}

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

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

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

case FLOAT:
case DOUBLE:
 return defaultValue.isNumber();
case BOOLEAN:
 return defaultValue.isBoolean();

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

return json.asInt();
else if ( json.isNumber() || json.isBoolean() ) {
  return BigInteger.valueOf( json.asLong() );

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

else if ( json.isNumber() || json.isBoolean() ) {
  return BigInteger.valueOf( json.asLong() );

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

else if ( ( ( JsonNode ) node ).isNumber() ) {
  node = ( ( JsonNode ) node ).asInt();

代码示例来源:origin: opentripplanner/OpenTripPlanner

if (timeout.isNumber()) {
  this.timeouts = new double[]{timeout.doubleValue()};
} else {

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

break;
case INT:
 if (!n.isNumber())
  throw new AvroTypeException("Non-numeric default value for int: "+n);
 e.writeInt(n.intValue());
 break;
case LONG:
 if (!n.isNumber())
  throw new AvroTypeException("Non-numeric default value for long: "+n);
 e.writeLong(n.longValue());
 break;
case FLOAT:
 if (!n.isNumber())
  throw new AvroTypeException("Non-numeric default value for float: "+n);
 e.writeFloat((float) n.doubleValue());
 break;
case DOUBLE:
 if (!n.isNumber())
  throw new AvroTypeException("Non-numeric default value for double: "+n);
 e.writeDouble(n.doubleValue());

代码示例来源:origin: opensourceBIM/BIMserver

private double checkFloat(ObjectNode node, String key) throws QueryException {
  if (!node.has(key)) {
    throw new QueryException("\"" + key + "\" not found on \"inBoundingBox\"");
  }
  JsonNode jsonNode = node.get(key);
  if (jsonNode.isNumber()) {
    return jsonNode.asDouble();
  } else {
    throw new QueryException("\"" + key + "\" should be of type number");
  }
}

相关文章