} else if (valueType == ValueType.DOUBLE && value.isDouble()) { return ValueReference.of(value.doubleValue()); } else if (valueType == ValueType.FLOAT && value.isFloat()) { return ValueReference.of(value.floatValue()); } else if (valueType == ValueType.INTEGER && value.isInt()) {
/** * Extracts float value from JsonNode if it is within bounds. * * <p>Throws {@link UnsupportedRowJsonException} if value is out of bounds. */ static ValueExtractor<Float> floatValueExtractor() { return ValidatingValueExtractor.<Float>builder() .setExtractor(JsonNode::floatValue) .setValidator( jsonNode -> jsonNode.isFloat() // Either floating number which allows lossless conversion to float || (jsonNode.isFloatingPointNumber() && jsonNode.doubleValue() == (double) (float) jsonNode.doubleValue()) // Or an integer number which allows lossless conversion to float || (jsonNode.isIntegralNumber() && jsonNode.canConvertToInt() && jsonNode.asInt() == (int) (float) jsonNode.asInt())) .build(); }
} else if (jsonNode.isDouble() || jsonNode.isFloat()) { if (schema == null || schema.getType().equals(Schema.Type.DOUBLE)) { return jsonNode.asDouble();
} else if (e.isDouble()) { return e.doubleValue(); } else if (e.isFloat()) { return e.floatValue(); } else if (e.isBigDecimal()) {
private String getPostgresqlType(JsonNode clazz) { if (clazz.isTextual()) { try { DateTimeUtils.parseDate(clazz.asText()); return "date"; } catch (Exception e) { } try { DateTimeUtils.parseTimestamp(clazz.asText()); return "timestamp"; } catch (Exception e) { } return "text"; } else if (clazz.isFloat() || clazz.isDouble()) { return "float8"; } else if (clazz.isNumber()) { return "int8"; } else if (clazz.isBoolean()) { return "bool"; } else if (clazz.isArray()) { if(clazz.get(0).isObject()){ return "jsonb"; } return getPostgresqlType(clazz.get(0)) + "[]"; } else if (clazz.isObject()) { return "jsonb"; } else { throw new IllegalArgumentException(); } }
} else if (e.isDouble()) { return e.doubleValue(); } else if (e.isFloat()) { return e.floatValue(); } else if (e.isBigDecimal()) {
private static boolean test(final JsonNode value) { if ((value.isDouble() || value.isFloat()) && Double.isNaN(value.asDouble())) return true; return false; } }
private static boolean test(final JsonNode value) { if ((value.isDouble() || value.isFloat()) && Double.isNaN(value.asDouble())) return true; return false; } }
private static boolean test(final JsonNode value) { if ((value.isDouble() || value.isFloat()) && Double.isInfinite(value.asDouble())) return true; return false; } }
private static boolean test(final JsonNode value) { if ((value.isDouble() || value.isFloat()) && Double.isInfinite(value.asDouble())) return true; return false; } }
@Override public Object parseJsonNode(JsonNode input, Schema schema) { Preconditions.checkState(input.isFloat() || input.isDouble(), "'%s' is not a '%s'", input.asText(), expectedClass().getSimpleName()); return input.decimalValue().doubleValue(); } }
@Override public Object parseJsonNode(JsonNode input, Schema schema) { Preconditions.checkState(input.isFloat() || input.isDouble(), "'%s' is not a '%s'", input.asText(), expectedClass().getSimpleName()); return input.decimalValue().floatValue(); } }
public Map<String, Object> getParams(JsonNode next) { if (next.has("params")) { Iterator<Entry<String, JsonNode>> it2 = next.get("params").fields(); Map<String, Object> params = new HashMap<String, Object>(); while (it2.hasNext()) { Entry<String, JsonNode> param = it2.next(); JsonNode value = param.getValue(); if (value.isTextual()) { params.put(param.getKey(), value.asText()); } else if (value.isInt()) { params.put(param.getKey(), value.asInt()); } else if (value.isBoolean()) { params.put(param.getKey(), value.asBoolean()); } else if (value.isDouble() || value.isFloat() || value.isBigDecimal()) { params.put(param.getKey(), value.asDouble()); } else if (value.isLong() || value.isBigInteger()) { params.put(param.getKey(), value.asLong()); } else { params.put(param.getKey(), value); } params.put(param.getKey(), param.getValue().asText()); } return params; } return null; }
public Map<String, Object> getParams(JsonNode next) { if (next.has("params")) { Iterator<Entry<String, JsonNode>> it2 = next.get("params").fields(); Map<String, Object> params = new HashMap<String, Object>(); while (it2.hasNext()) { Entry<String, JsonNode> param = it2.next(); JsonNode value = param.getValue(); if (value.isTextual()) { params.put(param.getKey(), value.asText()); } else if (value.isInt()) { params.put(param.getKey(), value.asInt()); } else if (value.isBoolean()) { params.put(param.getKey(), value.asBoolean()); } else if (value.isDouble() || value.isFloat() || value.isBigDecimal()) { params.put(param.getKey(), value.asDouble()); } else if (value.isLong() || value.isBigInteger()) { params.put(param.getKey(), value.asLong()); } else { params.put(param.getKey(), value); } params.put(param.getKey(), param.getValue().asText()); } return params; } return null; }
private DataType getNodeType(JsonNode node) { if (node.isTextual()) { return DataType.STRING; } else if (node.isBoolean()) { return DataType.BOOLEAN; } else if (node.isInt()) { return DataType.INT; } else if (node.isLong()) { return DataType.LONG; } else if (node.isFloat()) { return DataType.FLOAT; } else if (node.isDouble()) { return DataType.DOUBLE; } else { throw new UnsupportedOperationException("JSON DataType not supported."); } } }
/** * Constructor * * @param value Parameter value */ @JsonCreator public QueryParameter(JsonNode value) { this.value = value; this.isList = value.isArray(); if (value.isInt()) { this.type = ParameterType.INTEGER; } else if (value.isLong()) { this.type = ParameterType.LONG; } else if (value.isFloat()) { this.type = ParameterType.FLOAT; } else if (value.isDouble()) { this.type = ParameterType.DOUBLE; } else if (value.isBoolean()) { this.type = ParameterType.BOOLEAN; } else if (value.isNull()) { this.type = ParameterType.NULL; } else { this.type = ParameterType.STRING; } }
private EdmPrimitiveTypeKind guessPrimitiveTypeKind(final JsonNode node) { return node.isShort() ? EdmPrimitiveTypeKind.Int16 : node.isInt() ? EdmPrimitiveTypeKind.Int32 : node.isLong() ? EdmPrimitiveTypeKind.Int64 : node.isBoolean() ? EdmPrimitiveTypeKind.Boolean : node.isFloat() ? EdmPrimitiveTypeKind.Single : node.isDouble() ? EdmPrimitiveTypeKind.Double : node.isBigDecimal() ? EdmPrimitiveTypeKind.Decimal : EdmPrimitiveTypeKind.String; }
private EdmPrimitiveTypeKind guessPrimitiveTypeKind(final JsonNode node) { return node.isShort() ? EdmPrimitiveTypeKind.Int16 : node.isInt() ? EdmPrimitiveTypeKind.Int32 : node.isLong() ? EdmPrimitiveTypeKind.Int64 : node.isBoolean() ? EdmPrimitiveTypeKind.Boolean : node.isFloat() ? EdmPrimitiveTypeKind.Single : node.isDouble() ? EdmPrimitiveTypeKind.Double : node.isBigDecimal() ? EdmPrimitiveTypeKind.Decimal : EdmPrimitiveTypeKind.String; }
private RelationalOperand parseRelationalOperand(JsonNode node) { Object value; if (node.isTextual()) { value = node.textValue(); } else if (node.isBoolean()) { value = node.booleanValue(); } else if (node.isInt()) { value = node.intValue(); } else if (node.isLong()) { value = node.longValue(); } else if (node.isBigInteger()) { value = node.bigIntegerValue(); } else if (node.isFloat()) { value = node.floatValue(); } else if (node.isDouble()) { value = node.doubleValue(); } else if (node.isBigDecimal()) { value = node.decimalValue(); } else if (node.isNull()) { value = null; } else { throw new IllegalArgumentException("Unexpected value of: " + node); } return new Value(value); }
@Override protected Number _fromJson(JsonNode json) { if (json.isBigDecimal()) { return json.decimalValue(); } else if (json.isBigInteger()) { return json.bigIntegerValue(); } // no methods for Byte, even though numberNode(Byte) is provided. // experimentations shows that bytes show up as ints. Oh well.. else if (json.isDouble()) { return json.doubleValue(); } else if (json.isFloat()) { return json.floatValue(); } else if (json.isInt()) { return json.intValue(); } else if (json.isLong()) { return json.longValue(); } else if (json.isShort()) { return json.shortValue(); } else { return null; } }