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

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

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

JsonNode.isInt介绍

[英]Method that can be used to check whether contained value is a number represented as Java int. Note, however, that even if this method returns false, it is possible that conversion would be possible from other numeric types -- to check if this is possible, use #canConvertToInt() instead.
[中]方法,该方法可用于检查所包含的值是否为表示为Javaint的数字。但是,请注意,即使此方法返回false,也有可能从其他数值类型进行转换——要检查这是否可行,请使用#canConvertToInt()代替。

代码示例

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

private static QueryParsingException buildQueryParsingException(Supplier<String> errorMessage,
                                JsonNode rootCause,
                                List<String> reasons) {
  final JsonNode lineJson = rootCause.path("line");
  final Integer line = lineJson.isInt() ? lineJson.asInt() : null;
  final JsonNode columnJson = rootCause.path("col");
  final Integer column = columnJson.isInt() ? columnJson.asInt() : null;
  final String index = rootCause.path("index").asText(null);
  return new QueryParsingException(errorMessage.get(), line, column, index, reasons);
}

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

/**
 * Parse the output from the credentials process.
 */
private JsonNode parseProcessOutput(String processOutput) {
  JsonNode credentialsJson = Jackson.jsonNodeOf(processOutput);
  if (!credentialsJson.isObject()) {
    throw new IllegalStateException("Process did not return a JSON object.");
  }
  JsonNode version = credentialsJson.get("Version");
  if (version == null || !version.isInt() || version.asInt() != 1) {
    throw new IllegalStateException("Unsupported credential version: " + version);
  }
  return credentialsJson;
}

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

if (val.isInt() || val.isLong()) {
 return val.asLong();

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

if (typeNode.isTextual()) {
  type = symbolToValueType(typeNode.asText());
} else if (typeNode.isInt()) {
  type = intToValueType(typeNode.asInt());
} else {

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

@Override
  public Object getField(String fieldName) {
    JsonNode fn = jn.get(fieldName);
    if (fn.isContainerNode()) {
      AtomicInteger idx = new AtomicInteger(0);
      List<Field> fields = Lists.newArrayList(fn.fieldNames())
        .stream()
        .map(f -> new Field(f, idx.getAndIncrement()))
        .collect(Collectors.toList());
      return new GenericJsonRecord(fields, fn);
    } else if (fn.isBoolean()) {
      return fn.asBoolean();
    } else if (fn.isInt()) {
      return fn.asInt();
    } else if (fn.isFloatingPointNumber()) {
      return fn.asDouble();
    } else if (fn.isDouble()) {
      return fn.asDouble();
    } else {
      return fn.asText();
    }
  }
}

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

if (code == null || !code.isInt() || code.asInt() != ThrowableSerializationMixin.ERROR_CODE) {
 log.warn("Not resolving exception for unsupported error code {}", code);
 return null;

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

} else if (valueType == ValueType.FLOAT && value.isFloat()) {
  return ValueReference.of(value.floatValue());
} else if (valueType == ValueType.INTEGER && value.isInt()) {
  return ValueReference.of(value.intValue());
} else if (valueType == ValueType.LONG && (value.isLong() || value.isInt())) {

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

} else if (jsonNode.isBoolean()) {
 return jsonNode.asBoolean();
} else if (jsonNode.isInt()) {
 if (schema == null || schema.getType().equals(Schema.Type.INT)) {
  return jsonNode.asInt();

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

} else if (e.isBoolean()) {
  return e.asBoolean();
} else if (e.isInt()) {
  return e.asInt();
} else if (e.isLong()) {

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

} else if (type.equals("fixed")) {          // fixed
 JsonNode sizeNode = schema.get("size");
 if (sizeNode == null || !sizeNode.isInt())
  throw new SchemaParseException("Invalid or no size: "+schema);
 result = new FixedSchema(name, doc, sizeNode.intValue());

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

@Override
public int readI32() throws TException {
  final Class<?> fieldClass = getCurrentFieldClassIfIs(TEnum.class);
  if (fieldClass != null) {
    // Enum fields may be set by string, even though they represent integers.
    getCurrentContext().read();
    final JsonNode elem = getCurrentContext().getCurrentChild();
    if (elem.isInt()) {
      return TypedParser.INTEGER.readFromJsonElement(elem);
    } else if (elem.isTextual()) {
      // All TEnum are enums
      @SuppressWarnings({ "unchecked", "rawtypes" })
      final TEnum tEnum = (TEnum) Enum.valueOf((Class<Enum>) fieldClass,
                        TypedParser.STRING.readFromJsonElement(elem));
      return tEnum.getValue();
    } else {
      throw new TTransportException("invalid value type for enum field: " + elem.getNodeType() +
                     " (" + elem + ')');
    }
  } else {
    return readNameOrValue(TypedParser.INTEGER);
  }
}

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

/**
 * Parse the output from the credentials process.
 */
private JsonNode parseProcessOutput(String processOutput) {
  JsonNode credentialsJson = Jackson.jsonNodeOf(processOutput);
  if (!credentialsJson.isObject()) {
    throw new IllegalStateException("Process did not return a JSON object.");
  }
  JsonNode version = credentialsJson.get("Version");
  if (version == null || !version.isInt() || version.asInt() != 1) {
    throw new IllegalStateException("Unsupported credential version: " + version);
  }
  return credentialsJson;
}

代码示例来源:origin: fabric8io/kubernetes-client

@Override
public IntOrString deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException, JsonProcessingException {
  ObjectCodec oc = jsonParser.getCodec();
  JsonNode node = oc.readTree(jsonParser);
  IntOrString intOrString = new IntOrString();
  if (node.isInt()) {
    intOrString.setIntVal(node.asInt());
  } else {
    intOrString.setStrVal(node.asText());
  }
  return intOrString;
}

代码示例来源:origin: spring-projects/spring-data-rest

private Object valueFromJsonNode(String path, JsonNode valueNode) {

    if (valueNode == null || valueNode.isNull()) {
      return null;
    } else if (valueNode.isTextual()) {
      return valueNode.asText();
    } else if (valueNode.isFloatingPointNumber()) {
      return valueNode.asDouble();
    } else if (valueNode.isBoolean()) {
      return valueNode.asBoolean();
    } else if (valueNode.isInt()) {
      return valueNode.asInt();
    } else if (valueNode.isLong()) {
      return valueNode.asLong();
    } else if (valueNode.isObject() || (valueNode.isArray())) {
      return new JsonLateObjectEvaluator(mapper, valueNode);
    }

    throw new PatchException(
        String.format("Unrecognized valueNode type at path %s and value node %s.", path, valueNode));
  }
}

代码示例来源:origin: com.jayway.jsonpath/json-path

} else if (e.isBoolean()) {
  return e.asBoolean();
} else if (e.isInt()) {
  return e.asInt();
} else if (e.isLong()) {

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

private static QueryParsingException buildQueryParsingException(Supplier<String> errorMessage,
                                JsonNode rootCause,
                                List<String> reasons) {
  final JsonNode lineJson = rootCause.path("line");
  final Integer line = lineJson.isInt() ? lineJson.asInt() : null;
  final JsonNode columnJson = rootCause.path("col");
  final Integer column = columnJson.isInt() ? columnJson.asInt() : null;
  final String index = rootCause.path("index").asText(null);
  return new QueryParsingException(errorMessage.get(), line, column, index, reasons);
}

代码示例来源:origin: DigitalPebble/storm-crawler

@Override
public void configure(Map stormConf, JsonNode paramNode) {
  JsonNode node = paramNode.get("maxDepth");
  if (node != null && node.isInt()) {
    maxDepth = node.intValue();
  } else {
    maxDepth = -1;
    LOG.warn("maxDepth parameter not found");
  }
}

相关文章