當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonNode.isNumber方法代碼示例

本文整理匯總了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());
	}
}
 
開發者ID:magrossi,項目名稱:es-log4j2-appender,代碼行數:24,代碼來源:ElasticSearchRestAppenderTest.java

示例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);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:24,代碼來源:ColumnTypeFactory.java

示例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);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:25,代碼來源:ColumnTypeFactory.java

示例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;
}
 
開發者ID:yaochi,項目名稱:pac4j-plus,代碼行數:32,代碼來源:JsonHelper.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: 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);
}
 
開發者ID:line,項目名稱:centraldogma,代碼行數:41,代碼來源:JsonNumEquals.java

示例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;
	}
}
 
開發者ID:networknt,項目名稱:openapi-parser,代碼行數:13,代碼來源:PrimitiveOverlay.java

示例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");
	}
}
 
開發者ID:networknt,項目名稱:openapi-parser,代碼行數:14,代碼來源:BigParseTest.java

示例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);
}
 
開發者ID:jahirfiquitiva,項目名稱:Android-DDP,代碼行數:32,代碼來源:Protocol.java

示例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;
}
 
開發者ID:vietj,項目名稱:reactive-pg-client,代碼行數:28,代碼來源:DataType.java

示例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;
}
 
開發者ID:line,項目名稱:centraldogma,代碼行數:59,代碼來源:JsonNumEquals.java

示例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);
}
 
開發者ID:line,項目名稱:centraldogma,代碼行數:43,代碼來源:RevisionJsonDeserializer.java


注:本文中的com.fasterxml.jackson.databind.JsonNode.isNumber方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。