本文整理了Java中com.fasterxml.jackson.databind.JsonNode.decimalValue()
方法的一些代码示例,展示了JsonNode.decimalValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.decimalValue()
方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.JsonNode
类名称:JsonNode
方法名:decimalValue
[英]Returns floating point value for this node (as BigDecimal), if and only if this node is numeric ( #isNumber returns true). For other types returns BigDecimal.ZERO
.
[中]返回此节点的浮点值(作为BigDecimal),当且仅当此节点为数字(#isNumber返回true)。对于其他类型,返回BigDecimal.ZERO
。
代码示例来源:origin: aws/aws-sdk-java
/**
* Converts the lhs and rhs JsonNodes to the numeric values
* and delegates to the matches method that operates on the
* numeric values alone.
*
* @param lhs Lhs expression
* @param rhs Rhs expression
* @return Boolean result of the matches method of the
* corresponding comparison operator
*/
@Override
public final boolean matches(JsonNode lhs, JsonNode rhs) {
return matches(lhs.decimalValue(), rhs.decimalValue());
}
代码示例来源:origin: redisson/redisson
@Override
public BigDecimal getDecimalValue() throws IOException, JsonParseException {
return currentNumericNode().decimalValue();
}
代码示例来源:origin: aws/aws-sdk-java
public BigDecimal getExpectedAsNumber() {
if(expected.isNumber()) {
return expected.decimalValue();
}
return null;
}
代码示例来源:origin: knowm/XChange
@Override
public KucoinDealOrder deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
JsonNode root = p.readValueAsTree();
if (root.isArray()) {
Long timestamp = root.get(0).asLong();
KucoinOrderType orderType = KucoinOrderType.valueOf(root.get(1).asText());
BigDecimal price = root.get(2).decimalValue();
BigDecimal amount = root.get(3).decimalValue();
BigDecimal volume = root.get(4).decimalValue();
return new KucoinDealOrder(timestamp, orderType, price, amount, volume);
} else {
throw new RuntimeException("KucoinDealOrder should have an array as root node!");
}
}
}
代码示例来源:origin: knowm/XChange
@Override
public KucoinActiveOrder deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
JsonNode root = p.readValueAsTree();
if (root.isArray()) {
Date timestamp = new Date(root.get(0).asLong());
KucoinOrderType orderType = KucoinOrderType.valueOf(root.get(1).asText());
BigDecimal price = root.get(2).decimalValue();
BigDecimal amount = root.get(3).decimalValue();
BigDecimal dealAmount = root.get(4).decimalValue(); // amount already filled
String orderOid = root.get(5).textValue();
return new KucoinActiveOrder(timestamp, orderType, price, amount, dealAmount, orderOid);
} else {
throw new RuntimeException("KucoinDealOrder should have an array as root node!");
}
}
}
代码示例来源:origin: java-json-tools/json-schema-validator
private static boolean valueIsLong(final JsonNode node)
{
if (!node.canConvertToLong())
return false;
if (NodeType.getNodeType(node) == NodeType.INTEGER)
return true;
return node.decimalValue().remainder(BigDecimal.ONE)
.compareTo(BigDecimal.ZERO) == 0;
}
代码示例来源:origin: java-json-tools/json-schema-validator
protected final ObjectNode digestedNumberNode(final JsonNode schema)
{
final ObjectNode ret = FACTORY.objectNode();
final JsonNode node = schema.get(keyword);
final boolean isLong = valueIsLong(node);
ret.put("valueIsLong", isLong);
if (isLong) {
ret.put(keyword, node.canConvertToInt()
? FACTORY.numberNode(node.intValue())
: FACTORY.numberNode(node.longValue()));
return ret;
}
final BigDecimal decimal = node.decimalValue();
ret.put(keyword, decimal.scale() == 0
? FACTORY.numberNode(decimal.toBigIntegerExact())
: node);
return ret;
}
}
代码示例来源:origin: json-path/JsonPath
return e.asLong();
} else if (e.isBigDecimal()) {
return e.decimalValue();
} else if (e.isDouble()) {
return e.doubleValue();
return e.floatValue();
} else if (e.isBigDecimal()) {
return e.decimalValue();
} else if (e.isNull()) {
return null;
代码示例来源:origin: org.springframework.boot/spring-boot
return (D) jsonNode.decimalValue();
代码示例来源:origin: java-json-tools/json-schema-validator
@Override
protected final void validateDecimal(final ProcessingReport report,
final MessageBundle bundle, final FullData data)
throws ProcessingException
{
final JsonNode node = data.getInstance().getNode();
final BigDecimal instanceValue = node.decimalValue();
final BigDecimal decimalValue = number.decimalValue();
final BigDecimal remainder = instanceValue.remainder(decimalValue);
/*
* We cannot use equality! As far as BigDecimal goes,
* "0" and "0.0" are NOT equal. But .compareTo() returns the correct
* result.
*/
if (remainder.compareTo(BigDecimal.ZERO) == 0)
return;
report.error(newMsg(data, bundle, "err.common.divisor.nonZeroRemainder")
.putArgument("value", node).putArgument("divisor", number));
}
}
代码示例来源:origin: java-json-tools/json-schema-validator
@Override
protected void validateDecimal(final ProcessingReport report,
final MessageBundle bundle, final FullData data)
throws ProcessingException
{
final JsonNode instance = data.getInstance().getNode();
final BigDecimal instanceValue = instance.decimalValue();
final BigDecimal decimalValue = number.decimalValue();
final int cmp = instanceValue.compareTo(decimalValue);
if (cmp > 0)
return;
if (cmp < 0) {
report.error(newMsg(data, bundle, "err.common.minimum.tooSmall")
.putArgument(keyword, number).putArgument("found", instance));
return;
}
if (!exclusive)
return;
report.error(newMsg(data, bundle, "err.common.minimum.notExclusive")
.putArgument(keyword, number)
.put("exclusiveMinimum", BooleanNode.TRUE));
}
}
代码示例来源:origin: java-json-tools/json-schema-validator
@Override
protected void validateDecimal(final ProcessingReport report,
final MessageBundle bundle, final FullData data)
throws ProcessingException
{
final JsonNode instance = data.getInstance().getNode();
final BigDecimal instanceValue = instance.decimalValue();
final BigDecimal decimalValue = number.decimalValue();
final int cmp = instanceValue.compareTo(decimalValue);
if (cmp < 0)
return;
if (cmp > 0) {
report.error(newMsg(data, bundle, "err.common.maximum.tooLarge")
.putArgument(keyword, number).putArgument("found", instance));
return;
}
if (!exclusive)
return;
report.error(newMsg(data, bundle, "err.common.maximum.notExclusive")
.putArgument(keyword, number)
.put("exclusiveMaximum", BooleanNode.TRUE));
}
}
代码示例来源:origin: java-json-tools/json-schema-validator
private static Object valueToArgument(final JsonNode value)
{
final NodeType type = NodeType.getNodeType(value);
switch (type) {
case STRING:
return value.textValue();
case INTEGER:
return value.bigIntegerValue();
case NUMBER:
return value.decimalValue().toPlainString();
case NULL:
return value;
case BOOLEAN:
return value.booleanValue();
case ARRAY:
final List<Object> list = Lists.newArrayList();
for (final JsonNode element: value)
list.add(valueToArgument(element));
return list;
default:
throw new UnsupportedOperationException();
}
}
}
代码示例来源:origin: apache/hive
return (new DoubleWritable(value.doubleValue()));
case DECIMAL:
return (new HiveDecimalWritable(HiveDecimal.create(value.decimalValue())));
case CHAR:
return (new HiveCharWritable(new HiveChar(value.textValue(), ((CharTypeInfo) typeInfo).getLength())));
代码示例来源:origin: com.jayway.jsonpath/json-path
return e.asLong();
} else if (e.isBigDecimal()) {
return e.decimalValue();
} else if (e.isDouble()) {
return e.doubleValue();
return e.floatValue();
} else if (e.isBigDecimal()) {
return e.decimalValue();
} else if (e.isNull()) {
return null;
代码示例来源:origin: line/centraldogma
private static boolean numEquals(final JsonNode a, final JsonNode b) {
/*
* If both numbers are integers, delegate to JsonNode.
*/
if (a.isIntegralNumber() && b.isIntegralNumber()) {
return a.equals(b);
}
/*
* Otherwise, compare decimal values.
*/
return a.decimalValue().compareTo(b.decimalValue()) == 0;
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-common
private static boolean numEquals(final JsonNode a, final JsonNode b) {
/*
* If both numbers are integers, delegate to JsonNode.
*/
if (a.isIntegralNumber() && b.isIntegralNumber()) {
return a.equals(b);
}
/*
* Otherwise, compare decimal values.
*/
return a.decimalValue().compareTo(b.decimalValue()) == 0;
}
代码示例来源:origin: com.github.java-json-tools/jackson-coreutils
private static boolean numEquals(final JsonNode a, final JsonNode b)
{
/*
* If both numbers are integers, delegate to JsonNode.
*/
if (a.isIntegralNumber() && b.isIntegralNumber())
return a.equals(b);
/*
* Otherwise, compare decimal values.
*/
return a.decimalValue().compareTo(b.decimalValue()) == 0;
}
代码示例来源:origin: com.github.fge/jackson-coreutils
private static boolean numEquals(final JsonNode a, final JsonNode b)
{
/*
* If both numbers are integers, delegate to JsonNode.
*/
if (a.isIntegralNumber() && b.isIntegralNumber())
return a.equals(b);
/*
* Otherwise, compare decimal values.
*/
return a.decimalValue().compareTo(b.decimalValue()) == 0;
}
代码示例来源:origin: io.confluent.kafka/connect-utils
@Override
public Object parseJsonNode(JsonNode input, Schema schema) {
Preconditions.checkState(input.isFloat() || input.isDouble(), "'%s' is not a '%s'", input.asText(), expectedClass().getSimpleName());
return input.decimalValue().doubleValue();
}
}
内容来源于网络,如有侵权,请联系作者删除!