protected PositiveIntegerValidator(final String keyword, final JsonNode digest) { super(keyword); intValue = digest.get(keyword).intValue(); }
/** * 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(); } }
@Override public int getIntValue() throws IOException, JsonParseException { return currentNumericNode().intValue(); }
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()); }
public AdditionalItemsValidator(final JsonNode digest) { super("additionalItems"); additionalOK = digest.get(keyword).booleanValue(); itemsSize = digest.get("itemsSize").intValue(); }
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(); }
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; } }
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; } }
@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(); }
return (D) Integer.valueOf(jsonNode.intValue());
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())) {
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"));
@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"); }
@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()); }
@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"); }
@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()); }
@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"); }
@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")); }
if (!n.isNumber()) throw new AvroTypeException("Non-numeric default value for int: "+n); e.writeInt(n.intValue()); break; case LONG: