com.fasterxml.jackson.databind.JsonNode.doubleValue()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(125)

本文整理了Java中com.fasterxml.jackson.databind.JsonNode.doubleValue()方法的一些代码示例,展示了JsonNode.doubleValue()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.doubleValue()方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.JsonNode
类名称:JsonNode
方法名:doubleValue

JsonNode.doubleValue介绍

[英]Returns 64-bit floating point (double) value for this node, if and only if this node is numeric ( #isNumber returns true). For other types returns 0.0. For integer values, conversion is done using coercion; this may result in overflows with BigInteger values.
[中]返回此节点的64位浮点(双精度)值,当且仅当此节点为数字(#isNumber返回true)。对于其他类型,返回0.0。对于整数值,使用强制进行转换;这可能会导致BigInteger值溢出。

代码示例

代码示例来源:origin: redisson/redisson

@Override
public double getDoubleValue() throws IOException, JsonParseException {
  return currentNumericNode().doubleValue();
}

代码示例来源:origin: redisson/redisson

@Override
public float getFloatValue() throws IOException, JsonParseException {
  return (float) currentNumericNode().doubleValue();
}

代码示例来源:origin: apache/avro

private boolean defaultValueEquals(JsonNode thatDefaultValue) {
 if (defaultValue == null)
  return thatDefaultValue == null;
 if (thatDefaultValue == null)
  return false;
 if (Double.isNaN(defaultValue.doubleValue()))
  return Double.isNaN(thatDefaultValue.doubleValue());
 return defaultValue.equals(thatDefaultValue);
}

代码示例来源:origin: apache/geode

public ListAssert<Double> hasJsonArrayOfDoubles() throws IOException {
 JsonNode array = getJsonObject();
 List<Double> list = new ArrayList<>();
 for (int i = 0; i < array.size(); i++) {
  list.add(array.get(i).doubleValue());
 }
 return assertThat(list);
}

代码示例来源:origin: prestodb/presto

@Override
public double getDouble()
{
  try {
    if (value.isNumber()) {
      return value.doubleValue();
    }
    if (value.isValueNode()) {
      return parseDouble(value.asText());
    }
  }
  catch (NumberFormatException ignore) {
    // ignore
  }
  throw new PrestoException(
      DECODER_CONVERSION_NOT_SUPPORTED,
      format("could not parse value '%s' as '%s' for column '%s'", value.asText(), columnHandle.getType(), columnHandle.getName()));
}

代码示例来源:origin: opentripplanner/OpenTripPlanner

private void parseJson(String data) throws ParserConfigurationException, SAXException,
    IOException {
  ArrayList<BikeRentalStation> out = new ArrayList<BikeRentalStation>();
  // Jackson ObjectMapper to read in JSON
  // TODO: test against real data
  ObjectMapper mapper = new ObjectMapper();
  for (JsonNode stationNode : mapper.readTree(data)) {
    BikeRentalStation brStation = new BikeRentalStation();
    // We need string IDs but they are in JSON as numbers. Avoid null from textValue(). See pull req #1450.
    brStation.id = String.valueOf(stationNode.get("id").intValue());
    brStation.x = stationNode.get("lng").doubleValue() / 1000000.0;
    brStation.y = stationNode.get("lat").doubleValue() / 1000000.0;
    brStation.name = new NonLocalizedString(stationNode.get("name").textValue());
    brStation.bikesAvailable = stationNode.get("bikes").intValue();
    brStation.spacesAvailable = stationNode.get("free").intValue();
    if (brStation != null && brStation.id != null) {
      out.add(brStation);
    }
  }
  synchronized (this) {
    stations = out;
  }
}

代码示例来源:origin: org.springframework.boot/spring-boot

return (D) Double.valueOf(jsonNode.doubleValue());

代码示例来源:origin: Graylog2/graylog2-server

return ValueReference.of(value.booleanValue());
} else if (valueType == ValueType.DOUBLE && value.isDouble()) {
  return ValueReference.of(value.doubleValue());
} else if (valueType == ValueType.FLOAT && value.isFloat()) {
  return ValueReference.of(value.floatValue());

代码示例来源:origin: json-path/JsonPath

return e.decimalValue();
} else if (e.isDouble()) {
  return e.doubleValue();
} else if (e.isFloat()) {
  return e.floatValue();

代码示例来源:origin: opentripplanner/OpenTripPlanner

if (timeout != null) {
  if (timeout.isNumber()) {
    this.timeouts = new double[]{timeout.doubleValue()};
  } else {
    LOG.error("The 'timeout' configuration option should be a number of seconds.");
    int i = 0;
    for (JsonNode node : timeouts) {
      this.timeouts[i++] = node.doubleValue();

代码示例来源:origin: apache/hive

return (new FloatWritable(value.floatValue()));
case DOUBLE:
 return (new DoubleWritable(value.doubleValue()));
case DECIMAL:
 return (new HiveDecimalWritable(HiveDecimal.create(value.decimalValue())));

代码示例来源:origin: stagemonitor/stagemonitor

@Test
public void getMeter() throws Exception {
  registry.meter(name("foo").tag("bar", "baz").build()).mark();
  final MockHttpServletResponse resp = new MockHttpServletResponse();
  servlet.doGet(new MockHttpServletRequest(), resp);
  final double mean_rate = JsonUtils.getMapper().readTree(resp.getContentAsString()).get(0).get("values").get("mean_rate").doubleValue();
  assertTrue("Expected m1 rate of > 0, but got " + mean_rate, mean_rate > 0);
}

代码示例来源:origin: apache/avro

if (!n.isNumber())
  throw new AvroTypeException("Non-numeric default value for float: "+n);
 e.writeFloat((float) n.doubleValue());
 break;
case DOUBLE:
 if (!n.isNumber())
  throw new AvroTypeException("Non-numeric default value for double: "+n);
 e.writeDouble(n.doubleValue());
 break;
case BOOLEAN:

代码示例来源:origin: apache/avro

case VALUE_NUMBER_FLOAT:
 out.writeIndex(JsonType.DOUBLE.ordinal());
 out.writeDouble(node.doubleValue());
 break;
case VALUE_STRING:

代码示例来源:origin: com.jayway.jsonpath/json-path

return e.decimalValue();
} else if (e.isDouble()) {
  return e.doubleValue();
} else if (e.isFloat()) {
  return e.floatValue();

代码示例来源:origin: org.n52.arctic-sea/svalbard-json

private QuantityValue parseQuantityValue(JsonNode node)
    throws DecodingException {
  return new QuantityValue(node.path(JSONConstants.VALUE).doubleValue(),
      node.path(JSONConstants.UOM).textValue());
}

代码示例来源:origin: com.squarespace.template/template-plugins-squarespace

@Override
 public void apply(Context ctx, Arguments args, Variables variables) throws CodeExecuteException {
  Variable var = variables.first();
  double subtotalCents = var.node().path("subtotalCents").doubleValue();
  StringBuilder buf = new StringBuilder();
  buf.append("<span class=\"sqs-cart-subtotal\">");
  CommerceUtils.writeLegacyMoneyString(subtotalCents, buf);
  buf.append("</span>");
  var.set(buf);
 }
}

代码示例来源:origin: schibsted/jslt

public JsonNode call(JsonNode input, JsonNode[] arguments) {
  JsonNode number = arguments[0];
  if (number.isNull())
   return NullNode.instance;
  else if (!number.isNumber())
   throw new JsltException("round() cannot round a non-number: " + number);
  return new LongNode(Math.round(number.doubleValue()));
 }
}

代码示例来源:origin: org.n52.arctic-sea/svalbard-json

protected SweAbstractDataComponent decodeQuantity(JsonNode node) {
  SweQuantity swe = new SweQuantity();
  if (node.hasNonNull(JSONConstants.VALUE)) {
    swe.setValue(node.path(JSONConstants.VALUE).doubleValue());
  }
  return swe.setUom(node.path(JSONConstants.UOM).textValue());
}

代码示例来源:origin: org.apache.taverna.engine/taverna-workflowmodel-extensions

@Override
public void configure(JsonNode config) {
  ObjectNode defaultConfig = defaultConfig();
  setAllMissingFields((ObjectNode) config, defaultConfig);
  checkConfig((ObjectNode)config);
  this.config = (ObjectNode) config;
  maxRetries = config.get(MAX_RETRIES).intValue();
  initialDelay = config.get(INITIAL_DELAY).intValue();
  maxDelay = config.get(MAX_DELAY).intValue();
  backoffFactor = config.get(BACKOFF_FACTOR).doubleValue();       
}

相关文章