Java Code Examples for com.fasterxml.jackson.databind.JsonNode#asDouble()
The following examples show how to use
com.fasterxml.jackson.databind.JsonNode#asDouble() .
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: 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 2
Source File: TestVariableResolver.java From apiman with Apache License 2.0 | 6 votes |
/** * @see org.mvel2.integration.VariableResolver#getValue() */ @Override public Object getValue() { JsonNode varNode = node.get(fieldName); if (varNode.isObject()) { return varNode; } else if (varNode.isArray()) { List<Object> rval = new ArrayList<>(); for (int idx = 0; idx < varNode.size(); idx++) { JsonNode idxNode = varNode.get(idx); rval.add(idxNode); } return rval; } else if (varNode.isNull()) { return null; } else if (varNode.isBoolean()) { return varNode.asBoolean(); } else if (varNode.isTextual()) { return varNode.asText(); } else if (varNode.isInt()) { return varNode.asInt(); } else if (varNode.isDouble()) { return varNode.asDouble(); } return varNode; }
Example 3
Source File: CayenneExpParser.java From agrest with Apache License 2.0 | 6 votes |
private static Object extractValue(JsonNode valueNode) { JsonToken type = valueNode.asToken(); switch (type) { case VALUE_NUMBER_INT: return valueNode.asInt(); case VALUE_NUMBER_FLOAT: return valueNode.asDouble(); case VALUE_TRUE: return Boolean.TRUE; case VALUE_FALSE: return Boolean.FALSE; case VALUE_NULL: return null; case START_ARRAY: return extractArray(valueNode); default: // String parameters may need to be parsed further. Defer parsing // until it is placed in the context of an expression... return valueNode; } }
Example 4
Source File: JsonSerializable.java From azure-cosmosdb-java with MIT License | 6 votes |
static Object getValue(JsonNode value) { if (value.isValueNode()) { switch (value.getNodeType()) { case BOOLEAN: return value.asBoolean(); case NUMBER: if (value.isInt()) { return value.asInt(); } else if (value.isLong()) { return value.asLong(); } else if (value.isDouble()) { return value.asDouble(); } case STRING : return value.asText(); } } return value; }
Example 5
Source File: JsonUtils.java From search-spring-boot-starter with Apache License 2.0 | 6 votes |
public static Object parserValue(JsonNode node) { if (node == null || node.isNull()) { return null; } if (node.isArray()) { return parserArrayNode((ArrayNode) node); } else if (node.isObject()) { return parserMap((ObjectNode) node); } else { if (node.isBigDecimal() || node.isBigInteger() || node.isLong()) { return node.asLong(); } else if (node.isFloat() || node.isDouble()) { return node.asDouble(); } else if (node.isInt() || node.isNumber() || node.isShort()) { return node.asInt(); } else if (node.isBoolean()) { return node.asBoolean(); } else if (node.isTextual()) { return node.asText(); } else {// 其他类型 return node.textValue(); } } }
Example 6
Source File: OutputsCapturer.java From cwlexec with Apache License 2.0 | 6 votes |
private static Object toValueByJson(CWLTypeSymbol outputType, JsonNode jsonNode) { switch (outputType) { case STRING: return jsonNode.asText(); case INT: return jsonNode.asInt(); case FLOAT: return jsonNode.floatValue(); case DOUBLE: return jsonNode.asDouble(); case BOOLEAN: return jsonNode.asBoolean(); default: return null; } }
Example 7
Source File: SenchaFilterParser.java From agrest with Apache License 2.0 | 6 votes |
private static Object extractValue(JsonNode valueNode) { JsonToken type = valueNode.asToken(); // ExtJS converts everything to String except for NULL and booleans. So // follow the same logic here... // (http://docs.sencha.com/extjs/4.1.2/source/Filter.html#Ext-util-Filter) switch (type) { case VALUE_NULL: return null; case VALUE_FALSE: return false; case VALUE_TRUE: return true; case VALUE_NUMBER_INT: return valueNode.asInt(); case VALUE_NUMBER_FLOAT: return valueNode.asDouble(); case START_ARRAY: return extractArray(valueNode); default: return valueNode.asText(); } }
Example 8
Source File: GenericConverter.java From agrest with Apache License 2.0 | 6 votes |
@Override public Object value(JsonNode valueNode) { JsonToken type = valueNode.asToken(); switch (type) { case VALUE_NUMBER_INT: return valueNode.asInt(); case VALUE_NUMBER_FLOAT: return valueNode.asDouble(); case VALUE_TRUE: return Boolean.TRUE; case VALUE_FALSE: return Boolean.FALSE; case VALUE_NULL: return null; default: return valueNode.asText(); } }
Example 9
Source File: KsqlJsonDeserializer.java From ksql-fork-with-deep-learning-function with Apache License 2.0 | 5 votes |
private Object enforceFieldType(Schema fieldSchema, JsonNode fieldJsonNode) { if (fieldJsonNode.isNull()) { return null; } switch (fieldSchema.type()) { case BOOLEAN: return fieldJsonNode.asBoolean(); case INT32: return fieldJsonNode.asInt(); case INT64: return fieldJsonNode.asLong(); case FLOAT64: return fieldJsonNode.asDouble(); case STRING: if (fieldJsonNode.isTextual()) { return fieldJsonNode.asText(); } else { return fieldJsonNode.toString(); } case ARRAY: return handleArray(fieldSchema, (ArrayNode) fieldJsonNode); case MAP: return handleMap(fieldSchema, fieldJsonNode); default: throw new KsqlException("Type is not supported: " + fieldSchema.type()); } }
Example 10
Source File: SyncTokenDeserializer.java From syncope with Apache License 2.0 | 5 votes |
@Override public SyncToken deserialize(final JsonParser jp, final DeserializationContext ctx) throws IOException { ObjectNode tree = jp.readValueAsTree(); Object value = null; if (tree.has("value")) { JsonNode node = tree.get("value"); if (node.isBoolean()) { value = node.asBoolean(); } else if (node.isDouble()) { value = node.asDouble(); } else if (node.isLong()) { value = node.asLong(); } else if (node.isInt()) { value = node.asInt(); } else { value = node.asText(); } if (value instanceof String) { String base64 = (String) value; try { value = Base64.getDecoder().decode(base64); } catch (RuntimeException e) { value = base64; } } } return new SyncToken(Objects.requireNonNull(value)); }
Example 11
Source File: JsonQueryObjectModelConverter.java From BIMserver with GNU Affero General Public License v3.0 | 5 votes |
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"); } }
Example 12
Source File: FreegeoipProvider.java From play-geolocation-module.edulify.com with Apache License 2.0 | 5 votes |
private Geolocation asGeolocation(JsonNode json) { JsonNode jsonIp = json.get("ip"); JsonNode jsonCountryCode = json.get("country_code"); JsonNode jsonCountryName = json.get("country_name"); JsonNode jsonRegionCode = json.get("region_code"); JsonNode jsonRegionName = json.get("region_name"); JsonNode jsonCity = json.get("city"); JsonNode jsonLatitude = json.get("latitude"); JsonNode jsonLongitude = json.get("longitude"); JsonNode jsonTimeZone = json.get("time_zone"); if (jsonIp == null || jsonCountryCode == null || jsonCountryName == null || jsonRegionCode == null || jsonRegionName == null || jsonCity == null || jsonLatitude == null || jsonLongitude == null || jsonTimeZone == null) { return Geolocation.empty(); } return new Geolocation( jsonIp.asText(), jsonCountryCode.asText(), jsonCountryName.asText(), jsonRegionCode.asText(), jsonRegionName.asText(), jsonCity.asText(), jsonLatitude.asDouble(), jsonLongitude.asDouble(), jsonTimeZone.asText() ); }
Example 13
Source File: ShapeModelReflector.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
private Object getSimpleMemberValue(JsonNode currentNode, MemberModel memberModel) { if (memberModel.getHttp().getIsStreaming()) { return null; } switch (memberModel.getVariable().getSimpleType()) { case "Long": return currentNode.asLong(); case "Integer": return currentNode.asInt(); case "String": return currentNode.asText(); case "Boolean": return currentNode.asBoolean(); case "Double": return currentNode.asDouble(); case "Instant": return Instant.ofEpochMilli(currentNode.asLong()); case "SdkBytes": return SdkBytes.fromUtf8String(currentNode.asText()); case "Float": return (float) currentNode.asDouble(); case "Character": return asCharacter(currentNode); case "BigDecimal": return new BigDecimal(currentNode.asText()); default: throw new IllegalArgumentException( "Unsupported fieldType " + memberModel.getVariable().getSimpleType()); } }
Example 14
Source File: Instructions.java From template-compiler with Apache License 2.0 | 5 votes |
private static void emitJsonNode(StringBuilder buf, JsonNode node) { if (node.isNumber()) { // Formatting of numbers depending on type switch (node.numberType()) { case BIG_INTEGER: buf.append(((BigIntegerNode)node).bigIntegerValue().toString()); break; case BIG_DECIMAL: buf.append(((DecimalNode)node).decimalValue().toPlainString()); break; case INT: case LONG: buf.append(node.asLong()); break; case FLOAT: case DOUBLE: double val = node.asDouble(); buf.append(Double.toString(val)); break; default: break; } } else if (node.isArray()) { // JavaScript Array.toString() will comma-delimit the elements. for (int i = 0, size = node.size(); i < size; i++) { if (i >= 1) { buf.append(","); } buf.append(node.path(i).asText()); } } else if (!node.isNull() && !node.isMissingNode()) { buf.append(node.asText()); } }
Example 15
Source File: JsonObjectMapperDecoder.java From ffwd with Apache License 2.0 | 5 votes |
private double decodeDouble(JsonNode tree, String name) { final JsonNode n = tree.get(name); if (n == null) { return Double.NaN; } return n.asDouble(); }
Example 16
Source File: DataSetDeserializer.java From Sparkplug with Eclipse Public License 1.0 | 5 votes |
private Value<?> getValueFromNode(JsonNode nodeValue, DataSetDataType type) { switch (type) { case Boolean: return new Value<Boolean>(type, (boolean)nodeValue.asBoolean()); case DateTime: return new Value<Date>(type, new Date(nodeValue.asLong())); case Double: return new Value<Double>(type, nodeValue.asDouble()); case Float: return new Value<Float>(type, (float)nodeValue.asDouble()); case Int16: case UInt8: return new Value<Byte>(type, (byte)nodeValue.asInt()); case UInt16: case Int32: return new Value<Integer>(type, nodeValue.asInt()); case UInt32: case Int64: return new Value<Long>(type, (long)nodeValue.asLong()); case Text: case String: return new Value<String>(type, nodeValue.asText()); case UInt64: return new Value<BigInteger>(type, BigInteger.valueOf(nodeValue.asLong())); case Unknown: default: return null; } }
Example 17
Source File: IntentJsonMatcher.java From onos with Apache License 2.0 | 5 votes |
/** * Matches an annotation constraint against a JSON representation of the * constraint. * * @param annotationConstraint constraint object to match * @param constraintJson JSON representation of the constraint * @return true if the constraint and JSON match, false otherwise. */ private boolean matchAnnotationConstraint(AnnotationConstraint annotationConstraint, JsonNode constraintJson) { final JsonNode keyJson = constraintJson.get("key"); final JsonNode thresholdJson = constraintJson.get("threshold"); return (keyJson != null && keyJson.asText().equals(annotationConstraint.key())) && (thresholdJson != null && thresholdJson.asDouble() == annotationConstraint.threshold()); }
Example 18
Source File: GeneralUtils.java From template-compiler with Apache License 2.0 | 4 votes |
public static double ifDouble(JsonNode node, double defaultValue) { return isTruthy(node) ? node.asDouble() : defaultValue; }
Example 19
Source File: FunctionWrapper.java From jslt with Apache License 2.0 | 4 votes |
public Object convert(JsonNode node) { if (!node.isNumber()) throw new JsltException("Cannot convert " + node + " to double"); else return node.asDouble(); }
Example 20
Source File: GenericFilterExpander.java From samantha with MIT License | 4 votes |
public boolean compare(JsonNode value1, JsonNode value2) { return value1.asDouble() < value2.asDouble(); }