本文整理汇总了Java中com.fasterxml.jackson.databind.JsonNode.isNumber方法的典型用法代码示例。如果您正苦于以下问题:Java JsonNode.isNumber方法的具体用法?Java JsonNode.isNumber怎么用?Java JsonNode.isNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.JsonNode
的用法示例。
在下文中一共展示了JsonNode.isNumber方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: assertFieldValue
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Asserts that the fieldName field in node have the expected value.
*
* @param node the node
* @param fieldName the field name
* @param expected the expected
*/
private static void assertFieldValue(JsonNode node, String fieldName, Object expected) {
JsonNode field = node.get(fieldName);
assertNotNull(field);
assertTrue(field.isValueNode());
if (field.isNull()) {
assertNull(expected);
} else if (field.isTextual()) {
assertEquals(expected, field.asText());
} else if (field.isNumber()) {
assertEquals(expected, field.numberValue());
} else if (field.isBoolean()) {
assertEquals(expected, field.asBoolean());
} else {
assertEquals(expected.toString(), field.toString());
}
}
示例2: 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);
}
示例3: 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);
}
示例4: getElement
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Return the field with name in JSON as a string, a boolean, a number or a node.
*
* @param json json
* @param name node name
* @return the field
*/
public static Object getElement(final JsonNode json, final String name) {
if (json != null && name != null) {
JsonNode node = json;
for (String nodeName : name.split("\\.")) {
if (node != null) {
node = node.get(nodeName);
}
}
if (node != null) {
if (node.isNumber()) {
return node.numberValue();
} else if (node.isBoolean()) {
return node.booleanValue();
} else if (node.isTextual()) {
return node.textValue();
} else if (node.isNull()) {
return null;
} else {
return node;
}
}
}
return null;
}
示例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");
}
}
示例6: doEquivalent
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
protected boolean doEquivalent(final JsonNode a, final JsonNode b) {
/*
* If both are numbers, delegate to the helper method
*/
if (a.isNumber() && b.isNumber()) {
return numEquals(a, b);
}
final JsonNodeType typeA = a.getNodeType();
final JsonNodeType typeB = b.getNodeType();
/*
* If they are of different types, no dice
*/
if (typeA != typeB) {
return false;
}
/*
* For all other primitive types than numbers, trust JsonNode
*/
if (!a.isContainerNode()) {
return a.equals(b);
}
/*
* OK, so they are containers (either both arrays or objects due to the
* test on types above). They are obviously not equal if they do not
* have the same number of elements/members.
*/
if (a.size() != b.size()) {
return false;
}
/*
* Delegate to the appropriate method according to their type.
*/
return typeA == JsonNodeType.ARRAY ? arrayEquals(a, b) : objectEquals(a, b);
}
示例7: fromJson
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public Object fromJson(JsonNode json) {
if (json.isTextual()) {
return json.textValue();
} else if (json.isNumber()) {
return json.numberValue();
} else if (json.isBoolean()) {
return json.booleanValue();
} else {
return null;
}
}
示例8: getValue
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private Object getValue(JsonNode node) {
if (node.isNumber()) {
return node.numberValue();
} else if (node.isTextual()) {
return node.textValue();
} else if (node.isBoolean()) {
return node.booleanValue();
} else if (node.isNull()) {
return null;
} else {
throw new IllegalArgumentException("Non-value JSON node got through value node filter");
}
}
示例9: fromJson
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static Error fromJson(final JsonNode json) {
final String error;
if (json.has(Field.ERROR)) {
final JsonNode errorJson = json.get(Field.ERROR);
if (errorJson.isTextual()) {
error = errorJson.asText();
} else if (errorJson.isNumber()) {
error = String.valueOf(errorJson.asInt());
} else {
throw new IllegalArgumentException("Unexpected data type of error.error");
}
} else {
error = null;
}
final String reason;
if (json.has(Field.REASON)) {
reason = json.get(Field.REASON).asText();
} else {
reason = null;
}
final String details;
if (json.has(Field.DETAILS)) {
details = json.get(Field.DETAILS).asText();
} else {
details = null;
}
return new Error(error, reason, details);
}
示例10: decodeJson
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private static Object decodeJson(String value) {
int pos = 0;
while (pos < value.length() && Character.isWhitespace(value.charAt(pos))) {
pos++;
}
if (pos == value.length()) {
return null;
} else if (value.charAt(pos) == '{') {
return new JsonObject(value);
} else if (value.charAt(pos) == '[') {
return new JsonArray(value);
} else {
try {
JsonNode jsonNode = Json.mapper.readTree(value);
if (jsonNode.isNumber()) {
return jsonNode.numberValue();
} else if (jsonNode.isBoolean()) {
return jsonNode.booleanValue();
} else if (jsonNode.isTextual()) {
return jsonNode.textValue();
}
} catch (IOException e) {
// do nothing
}
}
return null;
}
示例11: doHash
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
protected int doHash(final JsonNode t) {
/*
* If this is a numeric node, we want the same hashcode for the same
* mathematical values. Go with double, its range is good enough for
* 99+% of use cases.
*/
if (t.isNumber()) {
return Double.valueOf(t.doubleValue()).hashCode();
}
/*
* If this is a primitive type (other than numbers, handled above),
* delegate to JsonNode.
*/
if (!t.isContainerNode()) {
return t.hashCode();
}
/*
* The following hash calculations work, yes, but they are poor at best.
* And probably slow, too.
*
* TODO: try and figure out those hash classes from Guava
*/
int ret = 0;
/*
* If the container is empty, just return
*/
if (t.size() == 0) {
return ret;
}
/*
* Array
*/
if (t.isArray()) {
for (final JsonNode element : t) {
ret = 31 * ret + doHash(element);
}
return ret;
}
/*
* Not an array? An object.
*/
final Iterator<Map.Entry<String, JsonNode>> iterator = t.fields();
Map.Entry<String, JsonNode> entry;
while (iterator.hasNext()) {
entry = iterator.next();
ret = 31 * ret + (entry.getKey().hashCode() ^ doHash(entry.getValue()));
}
return ret;
}
示例12: deserialize
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public Revision deserialize(JsonParser p, DeserializationContext ctx) throws IOException {
final JsonNode node = p.readValueAsTree();
if (node.isNumber()) {
validateRevisionNumber(ctx, node, "major", false);
return new Revision(node.intValue());
}
if (node.isTextual()) {
try {
return new Revision(node.textValue());
} catch (IllegalArgumentException e) {
ctx.reportInputMismatch(Revision.class, e.getMessage());
// Should never reach here.
throw new Error();
}
}
if (!node.isObject()) {
ctx.reportInputMismatch(Revision.class,
"A revision must be a non-zero integer or " +
"an object that contains \"major\" and \"minor\" properties.");
// Should never reach here.
throw new Error();
}
final JsonNode majorNode = node.get("major");
final JsonNode minorNode = node.get("minor");
final int major;
validateRevisionNumber(ctx, majorNode, "major", false);
major = majorNode.intValue();
if (minorNode != null) {
validateRevisionNumber(ctx, minorNode, "minor", true);
if (minorNode.intValue() != 0) {
ctx.reportInputMismatch(Revision.class,
"A revision must not have a non-zero \"minor\" property.");
}
}
return new Revision(major);
}