本文整理了Java中com.fasterxml.jackson.databind.JsonNode.intValue()
方法的一些代码示例,展示了JsonNode.intValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.intValue()
方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.JsonNode
类名称:JsonNode
方法名:intValue
[英]Returns integer 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 int operates.
[中]返回此节点的整数值,当且仅当此节点为数字时(#isNumber返回true)。对于其他类型,返回0。对于浮点数,使用默认Java强制来截断值,类似于从double转换为int的操作方式。
代码示例来源:origin: java-json-tools/json-schema-validator
protected PositiveIntegerValidator(final String keyword,
final JsonNode digest)
{
super(keyword);
intValue = digest.get(keyword).intValue();
}
代码示例来源:origin: aws/aws-sdk-java
/**
* Get an Integer field from the JSON.
*
* @param json JSON document.
* @param fieldName Field name to get.
* @return Integer value of field or null if not present.
*/
private Integer getIntegerField(JsonNode json, String fieldName) {
if (!json.has(fieldName)) {
return null;
}
return json.get(fieldName).intValue();
}
}
代码示例来源:origin: redisson/redisson
@Override
public int getIntValue() throws IOException, JsonParseException {
return currentNumericNode().intValue();
}
代码示例来源:origin: java-json-tools/json-schema-validator
protected DraftV3TypeKeywordValidator(final String keyword,
final JsonNode digested)
{
super(keyword);
for (final JsonNode element: digested.get(keyword))
types.add(NodeType.fromName(element.textValue()));
for (final JsonNode element: digested.get("schemas"))
schemas.add(element.intValue());
}
代码示例来源:origin: java-json-tools/json-schema-validator
public AdditionalItemsValidator(final JsonNode digest)
{
super("additionalItems");
additionalOK = digest.get(keyword).booleanValue();
itemsSize = digest.get("itemsSize").intValue();
}
代码示例来源:origin: java-json-tools/json-schema-validator
public ArraySchemaSelector(final JsonNode digest)
{
hasItems = digest.get("hasItems").booleanValue();
itemsIsArray = digest.get("itemsIsArray").booleanValue();
itemsSize = digest.get("itemsSize").intValue();
hasAdditional = digest.get("hasAdditional").booleanValue();
}
代码示例来源:origin: opentripplanner/OpenTripPlanner
private void parseJson(String data) throws ParserConfigurationException, SAXException,
IOException {
ArrayList<BikeRentalStation> out = new ArrayList<BikeRentalStation>();
// Jackson ObjectMapper to read in JSON
// TODO: test against real data
ObjectMapper mapper = new ObjectMapper();
for (JsonNode stationNode : mapper.readTree(data)) {
BikeRentalStation brStation = new BikeRentalStation();
// We need string IDs but they are in JSON as numbers. Avoid null from textValue(). See pull req #1450.
brStation.id = String.valueOf(stationNode.get("id").intValue());
brStation.x = stationNode.get("lng").doubleValue() / 1000000.0;
brStation.y = stationNode.get("lat").doubleValue() / 1000000.0;
brStation.name = new NonLocalizedString(stationNode.get("name").textValue());
brStation.bikesAvailable = stationNode.get("bikes").intValue();
brStation.spacesAvailable = stationNode.get("free").intValue();
if (brStation != null && brStation.id != null) {
out.add(brStation);
}
}
synchronized (this) {
stations = out;
}
}
代码示例来源: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
@DataProvider
public Iterator<Object[]> testData()
throws ProcessingException, JsonPointerException
{
final List<Object[]> list = Lists.newArrayList();
JsonNode digest;
int elementIndex;
List<JsonPointer> ret;
for (final JsonNode node: testNode) {
digest = node.get("digest");
elementIndex = node.get("elementIndex").intValue();
ret = Lists.newArrayList();
for (final JsonNode element: node.get("ret"))
ret.add(new JsonPointer(element.textValue()));
list.add(new Object[]{ digest, elementIndex, ret });
}
return list.iterator();
}
代码示例来源:origin: org.springframework.boot/spring-boot
return (D) Integer.valueOf(jsonNode.intValue());
代码示例来源:origin: Graylog2/graylog2-server
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: actorapp/actor-platform
int attrId = attr.get("id").intValue();
String attrName = attr.get("name").textValue();
SchemeType attrType = loadType(attr.get("type"));
int attrId = attr.get("id").intValue();
String attrName = attr.get("name").textValue();
SchemeType attrType = loadType(attr.get("type"));
int attrId = attr.get("id").intValue();
String attrName = attr.get("name").textValue();
SchemeType attrType = loadType(attr.get("type"));
int attrId = attr.get("id").intValue();
String attrName = attr.get("name").textValue();
SchemeType attrType = loadType(attr.get("type"));
int attrId = attr.get("id").intValue();
String attrName = attr.get("name").textValue();
SchemeType attrType = loadType(attr.get("type"));
JsonNode attributes = content.get("values");
for (JsonNode attr : attributes) {
int attrId = attr.get("id").intValue();
String attrName = attr.get("name").textValue();
entity.getRecord().add(new SchemeEnum.Record(attrName, attrId));
int attrId = attr.get("id").intValue();
String attrName = attr.get("name").textValue();
SchemeType attrType = loadType(attr.get("type"));
代码示例来源:origin: stagemonitor/stagemonitor
@Test
public void reportSpan() throws Exception {
reporter.report(mock(SpanContextInformation.class), getSpan(100));
elasticsearchClient.waitForCompletion();
refresh();
final JsonNode hits = elasticsearchClient.getJson("/stagemonitor-spans*/_search").get("hits");
assertThat(hits.get("total").intValue()).as(hits.toString()).isEqualTo(1);
final JsonNode spanJson = hits.get("hits").elements().next().get("_source");
assertThat(spanJson.get("type").asText()).as(spanJson.toString()).isEqualTo("jdbc");
assertThat(spanJson.get("method").asText()).as(spanJson.toString()).isEqualTo("SELECT");
assertThat(spanJson.get("db.statement")).as(spanJson.toString()).isNotNull();
assertThat(spanJson.get("db.statement").asText()).as(spanJson.toString()).isEqualTo("SELECT * from STAGEMONITOR where 1 < 2");
assertThat(spanJson.get("duration_ms").asInt()).as(spanJson.toString()).isEqualTo(100);
assertThat(spanJson.get("name").asText()).as(spanJson.toString()).isEqualTo("ElasticsearchExternalSpanReporterIntegrationTest#test");
}
代码示例来源:origin: apache/hbase
@Test
public void testSearchJson() throws JsonProcessingException, IOException {
String jsonString = "{\"test\":[{\"data1\":100,\"data2\":\"hello\",\"data3\": [1 , 2 , 3]}, "
+ "{\"data4\":0}]}";
JsonNode node = JSONMetricUtil.mappStringToJsonNode(jsonString);
JsonNode r1 = JSONMetricUtil.searchJson(node, "data1");
JsonNode r2 = JSONMetricUtil.searchJson(node, "data2");
JsonNode r3 = JSONMetricUtil.searchJson(node, "data3");
JsonNode r4 = JSONMetricUtil.searchJson(node, "data4");
assertEquals(100, r1.intValue());
assertEquals("hello", r2.textValue());
assertEquals(1, r3.get(0).intValue());
assertEquals(0, r4.intValue());
}
代码示例来源:origin: stagemonitor/stagemonitor
@Test
public void testUpdateSpan() throws Exception {
final Span span = tracer.buildSpan("Test#test")
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
.start();
span.finish();
elasticsearchClient.waitForCompletion();
refresh();
reporter.updateSpan(B3HeaderFormat.getB3Identifiers(tracer, span), null, Collections.singletonMap("foo", "bar"));
refresh();
final JsonNode hits = elasticsearchClient.getJson("/stagemonitor-spans*/_search").get("hits");
assertThat(hits.get("total").intValue()).as(hits.toString()).isEqualTo(1);
final JsonNode spanJson = hits.get("hits").elements().next().get("_source");
assertThat(spanJson.get("foo").asText()).as(spanJson.toString()).isEqualTo("bar");
}
代码示例来源:origin: apache/hive
return new ByteWritable((byte) value.intValue());
case SHORT:
return (new ShortWritable(value.shortValue()));
case INT:
return new IntWritable(value.intValue());
case LONG:
return (new LongWritable((value.longValue())));
代码示例来源:origin: stagemonitor/stagemonitor
@Test
public void testSetReservedTagName() {
final SpanWrapper span = createTestSpan(1, s -> s.setTag("duration_ms", "foo"));
final ObjectNode jsonSpan = JsonUtils.toObjectNode(span);
assertEquals(jsonSpan.toString(), 1, jsonSpan.get("duration_ms").intValue());
}
代码示例来源:origin: stagemonitor/stagemonitor
@Test
public void testUpdateNotYetExistentSpan_eventuallyUpdates() throws Exception {
final Span span = tracer.buildSpan("Test#test")
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
.start();
reporter.updateSpan(B3HeaderFormat.getB3Identifiers(tracer, span), null, Collections.singletonMap("foo", "bar"));
span.finish();
elasticsearchClient.waitForCompletion();
refresh();
reporter.getUpdateReporter().flush();
refresh();
final JsonNode hits = elasticsearchClient.getJson("/stagemonitor-spans*/_search").get("hits");
assertThat(hits.get("total").intValue()).as(hits.toString()).isEqualTo(1);
final JsonNode spanJson = hits.get("hits").elements().next().get("_source");
assertThat(spanJson.get("foo").asText()).as(spanJson.toString()).isEqualTo("bar");
}
代码示例来源:origin: stagemonitor/stagemonitor
@Test
public void reportSpan() throws Exception {
final Map<String, String> parameters = new HashMap<>();
parameters.put("attr.Color", "Blue");
parameters.put("attr", "bla");
parameters.put("foo", "bar");
final Span span = tracer.buildSpan("Test#test")
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
.start();
SpanUtils.setParameters(span, parameters);
span.setTag(SpanUtils.OPERATION_TYPE, "method_invocation");
span.setTag("foo.bar", "baz");
span.finish();
elasticsearchClient.waitForCompletion();
refresh();
final JsonNode hits = elasticsearchClient.getJson("/stagemonitor-spans*/_search").get("hits");
assertThat(hits.get("total").intValue()).as(hits.toString()).isEqualTo(1);
validateSpanJson(hits.get("hits").elements().next().get("_source"));
}
代码示例来源:origin: apache/avro
if (!n.isNumber())
throw new AvroTypeException("Non-numeric default value for int: "+n);
e.writeInt(n.intValue());
break;
case LONG:
内容来源于网络,如有侵权,请联系作者删除!