Java Code Examples for com.fasterxml.jackson.databind.JsonNode#isFloatingPointNumber()
The following examples show how to use
com.fasterxml.jackson.databind.JsonNode#isFloatingPointNumber() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BeatsCodec.java From graylog-plugin-beats with GNU General Public License v3.0 | 6 votes |
@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(); } }
Example 2
Source File: EditEntityDialog.java From jetbrains-plugin-graph-database-support with Apache License 2.0 | 6 votes |
private Object readValue(JsonNode node) { if (node.isFloatingPointNumber()) { return node.asDouble(); } else if (node.isNumber()) { return node.asLong(); } else if (node.isBoolean()) { return node.asBoolean(); } else if (node.isTextual()) { return node.asText(); } else if (node.isArray()) { return StreamSupport.stream(node.spliterator(), false) .map(this::readValue) .collect(toList()); } return node.toString(); }
Example 3
Source File: GenericJsonRecord.java From pulsar with Apache License 2.0 | 6 votes |
@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(schemaVersion, fields, fn); } else if (fn.isBoolean()) { return fn.asBoolean(); } else if (fn.isFloatingPointNumber()) { return fn.asDouble(); } else if (fn.isBigInteger()) { if (fn.canConvertToLong()) { return fn.asLong(); } else { return fn.asText(); } } else if (fn.isNumber()) { return fn.numberValue(); } else { return fn.asText(); } }
Example 4
Source File: Converter.java From ovsdb with Eclipse Public License 1.0 | 6 votes |
public Object deserialize(final JsonNode node) { if (!node.isArray()) { switch (node.getNodeType()) { case BOOLEAN: return node.asBoolean(); case NUMBER: if (node.isFloatingPointNumber()) { return node.decimalValue(); } else { return node.bigIntegerValue(); } case STRING: return node.asText(); default: break; } } if (node.isArray() && node.get(0).isTextual() && ("uuid".equals(node.get(0).asText()) || "named-uuid".equals(node.get(0).asText()))) { return new UUID(node.get(1).asText()); } throw new IllegalArgumentException("not an atom node"); }
Example 5
Source File: JsonPatchPatchConverter.java From spring-sync with Apache License 2.0 | 6 votes |
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()) { return new JsonLateObjectEvaluator(valueNode); } else if (valueNode.isArray()) { // TODO: Convert valueNode to array } return null; }
Example 6
Source File: NumberValue.java From zentity with Apache License 2.0 | 5 votes |
/** * Serialize the attribute value from a JsonNode object to a String object. * * @return */ @Override public String serialize(JsonNode value) { if (value.isNull()) return "null"; else if (value.isIntegralNumber()) return value.bigIntegerValue().toString(); else if (value.isFloatingPointNumber()) return String.valueOf(value.doubleValue()); else return value.numberValue().toString(); }
Example 7
Source File: AtlasGraphSONUtility.java From atlas with Apache License 2.0 | 5 votes |
private static Object getTypedValueFromJsonNode(JsonNode node) { Object theValue = null; if (node != null && !node.isNull()) { if (node.isBoolean()) { theValue = node.booleanValue(); } else if (node.isDouble()) { theValue = node.doubleValue(); } else if (node.isFloatingPointNumber()) { theValue = node.floatValue(); } else if (node.isInt()) { theValue = node.intValue(); } else if (node.isLong()) { theValue = node.longValue(); } else if (node.isTextual()) { theValue = node.textValue(); } else if (node.isArray()) { // this is an array so just send it back so that it can be // reprocessed to its primitive components theValue = node; } else if (node.isObject()) { // this is an object so just send it back so that it can be // reprocessed to its primitive components theValue = node; } else { theValue = node.textValue(); } } return theValue; }
Example 8
Source File: ExecutionContextDeserializer.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
@Override public ExecutionContext deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); final ExecutionContext executionContext = new ExecutionContext(); final boolean dirty = node.get("dirty").asBoolean(); for (JsonNode valueNode : node.get("values")) { final JsonNode nodeValue = valueNode.fields().next().getValue(); final String nodeKey = valueNode.fields().next().getKey(); if (nodeValue.isNumber() && !nodeValue.isFloatingPointNumber() && nodeValue.canConvertToInt()) { executionContext.putInt(nodeKey, nodeValue.asInt()); } else if (nodeValue.isNumber() && !nodeValue.isFloatingPointNumber() && nodeValue.canConvertToLong()) { executionContext.putLong(nodeKey, nodeValue.asLong()); } else if (nodeValue.isFloatingPointNumber()) { executionContext.putDouble(nodeKey, nodeValue.asDouble()); } else if (nodeValue.isBoolean()) { executionContext.putString(nodeKey, String.valueOf(nodeValue.asBoolean())); } else if (nodeValue.isTextual()) { executionContext.putString(nodeKey, nodeValue.asText()); } else { executionContext.put(nodeKey, nodeValue.toString()); } } if (!dirty && executionContext.isDirty()) { executionContext.clearDirtyFlag(); } return executionContext; }
Example 9
Source File: AtlasGraphSONUtility.java From incubator-atlas with Apache License 2.0 | 5 votes |
private static Object getTypedValueFromJsonNode(JsonNode node) { Object theValue = null; if (node != null && !node.isNull()) { if (node.isBoolean()) { theValue = node.booleanValue(); } else if (node.isDouble()) { theValue = node.doubleValue(); } else if (node.isFloatingPointNumber()) { theValue = node.floatValue(); } else if (node.isInt()) { theValue = node.intValue(); } else if (node.isLong()) { theValue = node.longValue(); } else if (node.isTextual()) { theValue = node.textValue(); } else if (node.isArray()) { // this is an array so just send it back so that it can be // reprocessed to its primitive components theValue = node; } else if (node.isObject()) { // this is an object so just send it back so that it can be // reprocessed to its primitive components theValue = node; } else { theValue = node.textValue(); } } return theValue; }
Example 10
Source File: FloatConverter.java From agrest with Apache License 2.0 | 5 votes |
@Override protected Float valueNonNull(JsonNode node) { if (node.isTextual()) { String value = node.asText(); if ("NaN".equalsIgnoreCase(value)) { return Float.NaN; } else if ("infinity".equalsIgnoreCase(value) || "+infinity".equalsIgnoreCase(value)) { return Float.POSITIVE_INFINITY; } else if ("-infinity".equalsIgnoreCase(value)) { return Float.NEGATIVE_INFINITY; } } if (!node.isIntegralNumber() && !node.isFloatingPointNumber()) { throw new AgException(Status.BAD_REQUEST, "Expected numeric value, got: " + node.asText()); } Double doubleValue = node.asDouble(); if (Double.valueOf(0).equals(doubleValue)) { return 0f; } Double absDoubleValue = Math.abs(doubleValue); if (absDoubleValue < Float.MIN_VALUE || absDoubleValue > Float.MAX_VALUE) { throw new AgException(Status.BAD_REQUEST, "Value is either too small or too large for the java.lang.Float datatype: " + node.asText()); } return doubleValue.floatValue(); }
Example 11
Source File: Utils.java From link-move with Apache License 2.0 | 5 votes |
/** * @return For strings, number and booleans - returns value of java.lang.Comparable#compareTo * @throws RuntimeException for other types */ public static int compare(JsonNode node1, JsonNode node2) { if (hasComparableType(node1) && hasComparableType(node2) && ofEqualTypes(node1, node2)) { switch (node1.getNodeType()) { case STRING: { return node1.textValue().compareTo(node2.textValue()); } case BOOLEAN: { Boolean left = node1.asBoolean(), right = node2.asBoolean(); return left.compareTo(right); } case NUMBER: { if (node1.isIntegralNumber()) { Integer left = node1.asInt(), right = node2.asInt(); return left.compareTo(right); } else if (node1.isFloatingPointNumber()) { Double left = node1.asDouble(), right = node2.asDouble(); return left.compareTo(right); } // fall through } default: { // fall through } } } throw new RuntimeException("Unsupported comparable type: " + node1.getNodeType().name()); }
Example 12
Source File: BandwidthCapacity.java From onos with Apache License 2.0 | 5 votes |
/** * Available Bandwidth resource (Capacity). * * @return {@link Bandwidth} */ public Bandwidth capacity() { JsonNode v = object.path(CAPACITY); if (v.isIntegralNumber()) { return Bandwidth.mbps(v.asLong()); } else if (v.isFloatingPointNumber()) { return Bandwidth.mbps(v.asDouble()); } else { log.warn("Unexpected JsonNode for {}: {}", CAPACITY, v); return Bandwidth.mbps(v.asDouble()); } }
Example 13
Source File: Attribute.java From zentity with Apache License 2.0 | 4 votes |
private void validateScore(JsonNode value) throws ValidationException { if (!value.isNull() && !value.isFloatingPointNumber()) throw new ValidationException("'attributes." + this.name + ".score' must be a floating point number."); if (value.isFloatingPointNumber() && (value.floatValue() < 0.0 || value.floatValue() > 1.0)) throw new ValidationException("'attributes." + this.name + ".score' must be in the range of 0.0 - 1.0."); }
Example 14
Source File: IndexField.java From zentity with Apache License 2.0 | 4 votes |
private void validateQuality(JsonNode value) throws ValidationException { if (!value.isNull() && !value.isFloatingPointNumber()) throw new ValidationException("'indices." + this.index + "." + this.name + ".quality' must be a floating point number."); if (value.isFloatingPointNumber() && (value.floatValue() < 0.0 || value.floatValue() > 1.0)) throw new ValidationException("'indices." + this.index + "." + this.name + ".quality' must be in the range of 0.0 - 1.0."); }
Example 15
Source File: Matcher.java From zentity with Apache License 2.0 | 4 votes |
private void validateQuality(JsonNode value) throws ValidationException { if (!value.isNull() && !value.isFloatingPointNumber()) throw new ValidationException("'matchers." + this.name + ".quality' must be a floating point number."); if (value.isFloatingPointNumber() && (value.floatValue() < 0.0 || value.floatValue() > 1.0)) throw new ValidationException("'matchers." + this.name + ".quality' must be in the range of 0.0 - 1.0."); }