@Override public Double asDouble() { return !data.isNumber() ? null : data.asDouble(); }
@Override public Long asLong() { return !data.isNumber() ? null : data.asLong(); }
@Override public Integer asInt() { return !data.isNumber() ? null : data.asInt(); }
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; } }
public BigDecimal getExpectedAsNumber() { if(expected.isNumber()) { return expected.decimalValue(); } return null; }
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; } }
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()); } }
if (val.isNumber()) { return val.asDouble();
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); } } }
@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())); }
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; }
if (timestampNode.isValueNode() && !timestampNode.isNumber()) { log.warn(prefix + "has invalid \"timestamp\": {} (type: {})", timestampNode.asText(), timestampNode.getNodeType().name());
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()); } }
case FLOAT: case DOUBLE: return defaultValue.isNumber(); case BOOLEAN: return defaultValue.isBoolean();
return json.asInt(); else if ( json.isNumber() || json.isBoolean() ) { return BigInteger.valueOf( json.asLong() );
else if ( json.isNumber() || json.isBoolean() ) { return BigInteger.valueOf( json.asLong() );
else if ( ( ( JsonNode ) node ).isNumber() ) { node = ( ( JsonNode ) node ).asInt();
if (timeout.isNumber()) { this.timeouts = new double[]{timeout.doubleValue()}; } else {
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());
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"); } }