当前位置: 首页>>代码示例>>Java>>正文


Java JsonNode.asDouble方法代码示例

本文整理汇总了Java中com.fasterxml.jackson.databind.JsonNode.asDouble方法的典型用法代码示例。如果您正苦于以下问题:Java JsonNode.asDouble方法的具体用法?Java JsonNode.asDouble怎么用?Java JsonNode.asDouble使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.fasterxml.jackson.databind.JsonNode的用法示例。


在下文中一共展示了JsonNode.asDouble方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toStr

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * @param field
 * @return
 */
private static Object toStr(final Map.Entry<String, JsonNode> field) {
    JsonNode value = field.getValue();
    switch (value.getNodeType()) {
        case STRING:
            return value.asText();
        case NUMBER:
            if (value.toString().contains(".")) {
                return value.asDouble();
            } else {
                return value.asInt();
            }

        default:
            return value.toString();
    }
}
 
开发者ID:sarojaba,项目名称:prettytable4j,代码行数:21,代码来源:JsonParser.java

示例2: transToValue

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * convert into value.
 * @param valueNode the BaseType JsonNode
 * @param baseType BooleanBaseType or IntegerBaseType or RealBaseType or
 *            StringBaseType or UuidBaseType
 * @return Object the value of JsonNode
 */
public static Object transToValue(JsonNode valueNode, BaseType baseType) {
    if (baseType instanceof BooleanBaseType) {
        return valueNode.asBoolean();
    } else if (baseType instanceof IntegerBaseType) {
        return valueNode.asInt();
    } else if (baseType instanceof RealBaseType) {
        return valueNode.asDouble();
    } else if (baseType instanceof StringBaseType) {
        return valueNode.asText();
    } else if (baseType instanceof UuidBaseType) {
        if (valueNode.isArray()) {
            if (valueNode.size() == 2) {
                if (valueNode.get(0).isTextual()
                        && ("uuid".equals(valueNode.get(0).asText()) || "named-uuid"
                                .equals(valueNode.get(0).asText()))) {
                    return Uuid.uuid(valueNode.get(1).asText());
                }
            }
        } else {
            return new RefTableRow(((UuidBaseType) baseType).getRefTable(), valueNode);
        }
    }
    return null;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:32,代码来源:TransValueUtil.java

示例3: getRealBaseType

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * Get RealBaseType by the type value of JsonNode which contains the
 * constraints.
 * @param type the type value of JsonNode
 * @return RealBaseType
 */
private static RealBaseType getRealBaseType(JsonNode type) {
    double min = Double.MIN_VALUE;
    double max = Double.MAX_VALUE;
    Set<Double> enums = Sets.newHashSet();
    JsonNode node = type.get("minReal");
    if (node != null) {
        min = node.asDouble();
    }
    node = type.get("maxReal");
    if (node != null) {
        max = node.asDouble();
    }
    if (type.has("enum")) {
        JsonNode anEnum = type.get("enum").get(1);
        for (JsonNode n : anEnum) {
            enums.add(n.asDouble());
        }
    }
    return new RealBaseType(min, max, enums);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:27,代码来源:BaseTypeFactory.java

示例4: getJsonValue

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static Object getJsonValue(JsonNode input, String name, Class type, boolean isRequired, Object defaultValue) throws IllegalArgumentException {
  JsonNode node = input.findPath(name);

  if (node.isMissingNode() || node.isNull()) {
    if (isRequired) {
      throw new IllegalArgumentException(name + " is required!");
    } else {
      return defaultValue;
    }
  }

  if (type.equals(String.class)) {
    return node.textValue();
  }

  if (type.equals(Integer.class)) {
    return node.asInt();
  }

  if (type.equals(Long.class)) {
    return node.asLong();
  }

  if (type.equals(Boolean.class)) {
    return node.asBoolean();
  }

  if (type.equals(Double.class)) {
    return node.asDouble();
  }

  return node.asText();
}
 
开发者ID:SirAeroWN,项目名称:premier-wherehows,代码行数:34,代码来源:JsonUtil.java

示例5: checkFloat

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
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");
	}
}
 
开发者ID:shenan4321,项目名称:BIMplatform,代码行数:12,代码来源:JsonQueryObjectModelConverter.java

示例6: getSimpleMemberValue

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
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 "ByteBuffer":
            return ByteBuffer.wrap(currentNode.asText().getBytes(StandardCharsets.UTF_8));
        case "Float":
            return (float) currentNode.asDouble();
        case "Character":
            return asCharacter(currentNode);
        default:
            throw new IllegalArgumentException(
                    "Unsupported fieldType " + memberModel.getVariable().getSimpleType());
    }
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:29,代码来源:ShapeModelReflector.java

示例7: matchAnnotationConstraint

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * 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());
}
 
开发者ID:shlee89,项目名称:athena,代码行数:18,代码来源:IntentJsonMatcher.java

示例8: getNodeData

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public Object getNodeData(Schema schema, JsonNode node) {
    if (node == null || node.isNull()) {
        return null;
    }
    switch (schema.getType()) {
        case INT:
            Preconditions.checkArgument(node.isNumber());
            return node.asInt();
        case LONG:
            Preconditions.checkArgument(node.isNumber());
            return node.asLong();
        case BOOLEAN:
            Preconditions.checkArgument(node.isBoolean());
            return node.asBoolean();
        case DOUBLE:
            Preconditions.checkArgument(node.isNumber());
            return node.asDouble();
        case FLOAT:
            Preconditions.checkArgument(node.isNumber());
            return Double.valueOf(node.asDouble()).floatValue();
        case BYTES:
            Preconditions.checkArgument(node.isTextual());
            String base64 = node.asText();
            return ByteArray.fromBase64(base64);
        case ENUM:
            Preconditions.checkArgument(node.isTextual());
            String enumConst = node.asText();
            EnumSchema es = (EnumSchema) schema;
            return es.getConstant(enumConst);
        case STRING:
            Preconditions.checkArgument(node.isTextual());
            return node.asText();
        case MAP:
            return readMap((MapSchema) schema, node);
        case LIST:
            Preconditions.checkArgument(node.isArray());
            return readList((ListSchema) schema, node);
        case RECORD:
            Preconditions.checkArgument(node.isObject());
            return readRecord((RecordSchema) schema, node);
        case ANY:
            Preconditions.checkArgument(node.isObject());
            return readAny(node);
        default:
            throw new IllegalArgumentException("Unknown schema type " + schema.getType());
    }
}
 
开发者ID:atlascon,项目名称:travny,代码行数:48,代码来源:JsonReader.java

示例9: fromJsonNode

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private void fromJsonNode(JsonNode node) {
    JsonNodeType nodeType = node.getNodeType();

    switch (nodeType) {
        case STRING:
            type = Schema.Type.STRING;
            value = node.asText();
            break;

        case NUMBER:
            double number = node.asDouble();

            if (number == Math.floor(number)) {
                type = Schema.Type.INTEGER;
                value = (int) number;
            } else {
                type = Schema.Type.FLOAT;
                value = number;
            }
            break;

        case BOOLEAN:
            type = Schema.Type.BOOLEAN;
            value = node.asBoolean();
            break;

        case ARRAY:
            List<Node> list = new LinkedList<>();

            type = Schema.Type.LIST;

            for (int i = 0; i < node.size(); i++) {
                list.add(new Node(node.get(i)));
            }

            value = list;
            break;

        case OBJECT:
            Map<String, Node> struct = new HashMap<>();

            type = Schema.Type.STRUCT;

            for (Iterator<String> properties = node.fieldNames(); properties.hasNext(); ) {
                String property = properties.next();
                struct.put(property, new Node(node.get(property)));
            }

            value = struct;
            break;

        default:
            throw new RuntimeException("Unsupported JSON type");
    }
}
 
开发者ID:antology,项目名称:a6y-server,代码行数:56,代码来源:Node.java


注:本文中的com.fasterxml.jackson.databind.JsonNode.asDouble方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。