本文整理汇总了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();
}
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
示例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);
}
}
示例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.");
}
示例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();
}
示例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;
}
示例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());
}
}
示例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);
}
示例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);
}
示例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;
}