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


Java JsonNode.asInt方法代码示例

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


在下文中一共展示了JsonNode.asInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: createAtomicColumnType

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * Create AtomicColumnType entity.
 * @param json JsonNode
 * @return AtomicColumnType entity
 */
private static AtomicColumnType createAtomicColumnType(JsonNode json) {
    BaseType baseType = BaseTypeFactory.getBaseTypeFromJson(json, Type.KEY.type());
    int min = 1;
    int max = 1;
    JsonNode node = json.get("min");
    if (node != null && node.isNumber()) {
        min = node.asInt();
    }
    node = json.get("max");
    if (node != null) {
        if (node.isNumber()) {
            max = node.asInt();
        } else if (node.isTextual() && "unlimited".equals(node.asText())) {
            max = Integer.MAX_VALUE;
        }
    }
    return new AtomicColumnType(baseType, min, max);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:24,代码来源:ColumnTypeFactory.java

示例4: createKeyValuedColumnType

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * Create KeyValuedColumnType entity.
 * @param json JsonNode
 * @return KeyValuedColumnType entity
 */
private static KeyValuedColumnType createKeyValuedColumnType(JsonNode json) {
    BaseType keyType = BaseTypeFactory.getBaseTypeFromJson(json, Type.KEY.type());
    BaseType valueType = BaseTypeFactory.getBaseTypeFromJson(json, Type.VALUE.type());
    int min = 1;
    int max = 1;
    JsonNode node = json.get("min");
    if (node != null && node.isNumber()) {
        min = node.asInt();
    }
    node = json.get("max");
    if (node != null) {
        if (node.isNumber()) {
            max = node.asInt();
        } else if (node.isTextual() && "unlimited".equals(node.asText())) {
            max = Integer.MAX_VALUE;
        }
    }
    return new KeyValuedColumnType(keyType, valueType, min, max);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:25,代码来源:ColumnTypeFactory.java

示例5: getIntegerBaseType

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

示例6: getStringBaseType

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * Get StringBaseType by the type value of JsonNode which contains the
 * constraints.
 * @param type the type value of JsonNode
 * @return StringBaseType
 */
private static StringBaseType getStringBaseType(JsonNode type) {
    int minLength = Integer.MIN_VALUE;
    int maxLength = Integer.MAX_VALUE;
    Set<String> enums = Sets.newHashSet();
    JsonNode node = type.get("minLength");
    if (node != null) {
        minLength = node.asInt();
    }
    node = type.get("maxLength");
    if (node != null) {
        maxLength = node.asInt();
    }
    if (type.has("enum")) {
        JsonNode enumVal = type.get("enum");
        if (enumVal.isArray()) {
            JsonNode anEnum = enumVal.get(1);
            for (JsonNode n : anEnum) {
                enums.add(n.asText());
            }
        } else if (enumVal.isTextual()) {
            enums.add(enumVal.asText());
        }
    }
    return new StringBaseType(minLength, maxLength, enums);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:32,代码来源:BaseTypeFactory.java

示例7: 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

示例8: moveBuffersToBody

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public void moveBuffersToBody(ObjectNode scene, GlbBody body) throws Exception {
	// Modify the GLTF data to reference the buffer in the body instead of
	// external references.

	JsonNode buffersNode = scene.get("buffers");
	Iterator<String> fieldIter = buffersNode.fieldNames();
	while (fieldIter.hasNext()) {
		String fieldKey = fieldIter.next();
		JsonNode gltfBufferNode = buffersNode.get(fieldKey);
		JsonNode typeNode = gltfBufferNode.get("type");
		String typeText = typeNode.asText();
		if (typeText != null && !typeText.equals("arraybuffer")) {
			throw new Exception("buffer type " + typeText + " not supported: " + fieldKey);
		}
		JsonNode uriNode = gltfBufferNode.get("uri");
		String uri = uriNode.asText();

		JsonNode byteLengthNode = gltfBufferNode.get("byteLength");
		int byteLength = byteLengthNode.asInt();

		Part part = body.add(uri, byteLength);

		JsonNode extrasNode = gltfBufferNode.get("extras");
		if (extrasNode == null) {
			extrasNode = jsonNodeFactory.objectNode();
			((ObjectNode) gltfBufferNode).set("extras", extrasNode);
		}
		((ObjectNode) extrasNode).put("byteOffset", part.offset);

	}

}
 
开发者ID:shenan4321,项目名称:BIMplatform,代码行数:33,代码来源:Gltf2glbConvertor.java

示例9: requireIntField

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private int requireIntField(final JsonNode node, final String fieldName) {
    JsonNode value = requireField(node, fieldName);
    if (value.isInt()) {
        return value.asInt();
    }
    throw new RuntimeException("Value of JSON key/field \"" + fieldName + "\" is required to be an int.");
}
 
开发者ID:mgrand,项目名称:bigchaindb-java-driver,代码行数:8,代码来源:SignedBigchaindbTransactionImpl.java

示例10: requireIntValue

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private static int requireIntValue(@NotNull final JsonNode node, final String fieldName) {
    final JsonNode valueNode = requireValue(node, fieldName);
    ensureType(valueNode, JsonNodeType.NUMBER, fieldName);
    if (!valueNode.canConvertToInt()) {
        throw new RuntimeException("Value of " + fieldName + " must be an integer: " + node);
    }
    return valueNode.asInt();
}
 
开发者ID:mgrand,项目名称:crypto-shuffle,代码行数:9,代码来源:JsonUtil.java

示例11: getAsInteger

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * Geef node waarde als Integer.
 * @param parentNode parent node
 * @param nodeName naam van de node
 * @return waarde van de node als Integer
 */
static Integer getAsInteger(final JsonNode parentNode, final String nodeName) {
    final Integer result;
    final JsonNode theNode = parentNode.get(nodeName);
    if (theNode != null && !theNode.isNull() && !"".equals(theNode.asText())) {
        result = theNode.asInt();
    } else {
        result = null;
    }
    return result;
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:17,代码来源:JsonUtils.java

示例12: 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

示例13: decode

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * Creates an instance of {@link OchSignal} from JSON representation.
 *
 * @param obj JSON Object representing OchSignal
 * @return OchSignal
 * @throws IllegalArgumentException - if JSON object is ill-formed
 * @see OchSignalCodec#encode(OchSignal)
 */
public static OchSignal decode(ObjectNode obj) {
    final GridType gridType;
    final ChannelSpacing channelSpacing;
    final int spacingMultiplier;
    final int slotGranularity;

    String s;
    s = obj.get("channelSpacing").textValue();
    checkArgument(s != null, "ill-formed channelSpacing");
    channelSpacing = Enum.valueOf(ChannelSpacing.class, s);

    s = obj.get("gridType").textValue();
    checkArgument(s != null, "ill-formed gridType");
    gridType = Enum.valueOf(GridType.class, s);

    JsonNode node;
    node = obj.get("spacingMultiplier");
    checkArgument(node.canConvertToInt(), "ill-formed spacingMultiplier");
    spacingMultiplier = node.asInt();

    node = obj.get("slotGranularity");
    checkArgument(node.canConvertToInt(), "ill-formed slotGranularity");
    slotGranularity = node.asInt();

    return new OchSignal(gridType, channelSpacing, spacingMultiplier, slotGranularity);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:35,代码来源:OchSignalCodec.java

示例14: decodeCriterion

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public Criterion decodeCriterion(ObjectNode json) {
    JsonNode ethTypeNode = nullIsIllegal(json.get(CriterionCodec.ETH_TYPE),
                                      CriterionCodec.ETH_TYPE + MISSING_MEMBER_MESSAGE);
    int ethType;
    if (ethTypeNode.isInt()) {
        ethType = ethTypeNode.asInt();
    } else {
        ethType = Integer.decode(ethTypeNode.textValue());
    }
    return Criteria.matchEthType(ethType);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:13,代码来源:DecodeCriterionCodecHelper.java

示例15: matchPushHeaderInstruction

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * Matches the contents of a push header instruction.
 *
 * @param instructionJson JSON instruction to match
 * @param description Description object used for recording errors
 * @return true if contents match, false otherwise
 */
private boolean matchPushHeaderInstruction(JsonNode instructionJson,
                                           Description description) {
    PushHeaderInstructions instructionToMatch =
            (PushHeaderInstructions) instruction;
    final String jsonSubtype = instructionJson.get("subtype").textValue();
    if (!instructionToMatch.subtype().name().equals(jsonSubtype)) {
        description.appendText("subtype was " + jsonSubtype);
        return false;
    }

    final String jsonType = instructionJson.get("type").textValue();
    if (!instructionToMatch.type().name().equals(jsonType)) {
        description.appendText("type was " + jsonType);
        return false;
    }

    final JsonNode ethJson = instructionJson.get("ethernetType");
    if (ethJson == null) {
        description.appendText("ethernetType was not null");
        return false;
    }

    if (instructionToMatch.ethernetType().toShort() != ethJson.asInt()) {
        description.appendText("ethernetType was " + ethJson);
        return false;
    }

    return true;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:37,代码来源:InstructionJsonMatcher.java


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