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

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

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

JsonNode.asBoolean介绍

[英]Method that will try to convert value of this node to a Java boolean. JSON booleans map naturally; integer numbers other than 0 map to true, and 0 maps to false and Strings 'true' and 'false' map to corresponding values.

If representation cannot be converted to a boolean value (including structured types like Objects and Arrays), default value of false will be returned; no exceptions are thrown.
[中]方法,该方法将尝试将此节点的值转换为Java布尔值。JSON布尔映射自然;0以外的整数映射为true,0映射为false,字符串“true”和“false”映射为相应的值。
如果表示无法转换为布尔值(包括对象和数组等结构化类型),则返回默认值false;没有抛出异常。

代码示例

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

/**
 * Method that will try to convert value of this node to a Java <b>boolean</b>.
 * JSON booleans map naturally; integer numbers other than 0 map to true, and
 * 0 maps to false
 * and Strings 'true' and 'false' map to corresponding values.
 *<p>
 * If representation cannot be converted to a boolean value (including structured types
 * like Objects and Arrays),
 * default value of <b>false</b> will be returned; no exceptions are thrown.
 */
public boolean asBoolean() {
  return asBoolean(false);
}

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

protected boolean getValueAsBoolean(String name,
                  JsonNode objectNode) {
  boolean propertyValue = false;
  JsonNode propertyNode = objectNode.get(name);
  if (propertyNode != null && !propertyNode.isNull()) {
    propertyValue = propertyNode.asBoolean();
  }
  return propertyValue;
}

代码示例来源:origin: linlinjava/litemall

public static Boolean parseBoolean(String body, String field) {
  ObjectMapper mapper = new ObjectMapper();
  JsonNode node = null;
  try {
    node = mapper.readTree(body);
    JsonNode leaf = node.get(field);
    if (leaf != null)
      return leaf.asBoolean();
  } catch (IOException e) {
    e.printStackTrace();
  }
  return null;
}

代码示例来源:origin: joelittlejohn/jsonschema2pojo

private boolean isRequired(String nodeName, JsonNode node, Schema schema) {
  if (node.has("required")) {
    final JsonNode requiredNode = node.get("required");
    return requiredNode.asBoolean();
  }
  JsonNode requiredArray = schema.getContent().get("required");
  if (requiredArray != null) {
    for (JsonNode requiredNode : requiredArray) {
      if (nodeName.equals(requiredNode.asText()))
        return true;
    }
  }
  return false;
}

代码示例来源:origin: joelittlejohn/jsonschema2pojo

private boolean useOptional(String nodeName, JsonNode node, Schema schema) {
  if (node.has("javaOptional")) {
    final JsonNode requiredNode = node.get("javaOptional");
    return requiredNode.asBoolean();
  }
  JsonNode javaOptionalArray = schema.getContent().get("javaOptional");
  if (javaOptionalArray != null) {
    for (JsonNode requiredNode : javaOptionalArray) {
      if (nodeName.equals(requiredNode.asText()))
        return true;
    }
  }
  return false;
}

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

private boolean checkForReopened(@Nonnull JsonNode indexSettings, Version elasticsearchVersion) {
  final JsonNode settings;
  if (elasticsearchVersion.satisfies(">=2.1.0 & <5.0.0")) {
    settings = indexSettings;
  } else if (elasticsearchVersion.satisfies("^5.0.0 | ^6.0.0")) {
    settings = indexSettings.path("archived");
  } else {
    throw new ElasticsearchException("Unsupported Elasticsearch version: " + elasticsearchVersion);
  }
  // if this is a missing node, asBoolean() returns false
  return settings.path("index").path(REOPENED_INDEX_SETTING).asBoolean();
}

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

@Override
public boolean getBoolean()
{
  if (value.isValueNode()) {
    return value.asBoolean();
  }
  throw new PrestoException(
      DECODER_CONVERSION_NOT_SUPPORTED,
      format("could not parse non-value node as '%s' for column '%s'", columnHandle.getType(), columnHandle.getName()));
}

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

private Object toValue(JsonNode node)
      throws IOException
  {
    if (node.isTextual()) {
      return node.asText();
    }
    else if (node.isNumber()) {
      return node.numberValue();
    }
    else if (node.isBoolean()) {
      return node.asBoolean();
    }
    else if (node.isBinary()) {
      return node.binaryValue();
    }
    else {
      throw new IllegalStateException("Unexpected range bound value: " + node);
    }
  }
}

代码示例来源:origin: twosigma/beakerx

@Test
public void serializeBorderDisplayed_resultJsonHasBorderDisplayed() throws IOException {
 //given
 layoutManager.setBorderDisplayed(true);
 //when
 JsonNode actualObj = helper.serializeObject(layoutManager);
 //then
 Assertions.assertThat(actualObj.has("borderDisplayed")).isTrue();
 Assertions.assertThat(actualObj.get("borderDisplayed").asBoolean()).isTrue();
}

代码示例来源:origin: twosigma/beakerx

@Test
public void serializeCumulativeOfHistogram_resultJsonHasCumulative() throws IOException {
 //when
 histogram.setCumulative(true);
 histogramSerializer.serialize(histogram, jgen, new DefaultSerializerProvider.Impl());
 jgen.flush();
 //then
 JsonNode actualObj = mapper.readTree(sw.toString());
 Assertions.assertThat(actualObj.has("cumulative")).isTrue();
 Assertions.assertThat(actualObj.get("cumulative").asBoolean()).isTrue();
}

代码示例来源:origin: twosigma/beakerx

@Test
public void serializeLogXOfXYChartPlot_resultJsonHasLogX() throws IOException {
 //when
 plot.setLogX(true);
 xyChartSerializer.serialize(plot, jgen, new DefaultSerializerProvider.Impl());
 jgen.flush();
 //then
 JsonNode actualObj = mapper.readTree(sw.toString());
 Assertions.assertThat(actualObj.has("log_x")).isTrue();
 Assertions.assertThat(actualObj.get("log_x").asBoolean()).isTrue();
}

代码示例来源:origin: twosigma/beakerx

@Test
public void serializeAutoRangeOfYAxis_resultJsonHasAutoRange() throws IOException {
 //when
 yAxis.setAutoRange(true);
 yAxisSerializer.serialize(yAxis, jgen, new DefaultSerializerProvider.Impl());
 jgen.flush();
 //then
 JsonNode actualObj = mapper.readTree(sw.toString());
 Assertions.assertThat(actualObj.has("auto_range")).isTrue();
 Assertions.assertThat(actualObj.get("auto_range").asBoolean()).isTrue();
}

代码示例来源:origin: twosigma/beakerx

@Test
public void serializeClickActionLineGraphics_resultJsonHasClickAction() throws IOException {
 //when
 line.onClick(actionObject -> {});
 graphicsSerializer.serialize(line, jgen, new DefaultSerializerProvider.Impl());
 jgen.flush();
 //then
 JsonNode actualObj = mapper.readTree(sw.toString());
 Assertions.assertThat(actualObj.has("hasClickAction")).isTrue();
 Assertions.assertThat(actualObj.get("hasClickAction").asBoolean()).isTrue();
}

代码示例来源:origin: twosigma/beakerx

@Test
public void serializeShowPointerText_resultJsonHasShowPointer() throws IOException {
 //when
 text.setShowPointer(true);
 textSerializer.serialize(text, jgen, new DefaultSerializerProvider.Impl());
 jgen.flush();
 //then
 JsonNode actualObj = mapper.readTree(sw.toString());
 Assertions.assertThat(actualObj.has("show_pointer")).isTrue();
 Assertions.assertThat(actualObj.get("show_pointer").asBoolean()).isTrue();
}

代码示例来源:origin: twosigma/beakerx

@Test
public void serializeRoundOfTreeMap_resultJsonHasRound() throws IOException {
 //when
 treeMap.setRound(true);
 treeMapSerializer.serialize(treeMap, jgen, new DefaultSerializerProvider.Impl());
 jgen.flush();
 //then
 JsonNode actualObj = mapper.readTree(sw.toString());
 Assertions.assertThat(actualObj.has("round")).isTrue();
 Assertions.assertThat(actualObj.get("round").asBoolean()).isTrue();
}

代码示例来源:origin: twosigma/beakerx

@Test
public void serializeXTickLabelsVisibleOfXYChartPlot_resultJsonHasXTickLabelsVisible()
  throws IOException {
 //when
 plot.setxTickLabelsVisible(true);
 xyChartSerializer.serialize(plot, jgen, new DefaultSerializerProvider.Impl());
 jgen.flush();
 //then
 JsonNode actualObj = mapper.readTree(sw.toString());
 Assertions.assertThat(actualObj.has("x_tickLabels_visible")).isTrue();
 Assertions.assertThat(actualObj.get("x_tickLabels_visible").asBoolean()).isTrue();
}

代码示例来源:origin: twosigma/beakerx

@Test
public void serializeFillsPoints_resultJsonHasFills() throws IOException {
 //when
 points.setFill(Arrays.asList(false, true, false));
 pointsSerializer.serialize(points, jgen, new DefaultSerializerProvider.Impl());
 jgen.flush();
 //then
 JsonNode actualObj = mapper.readTree(sw.toString());
 Assertions.assertThat(actualObj.has("fills")).isTrue();
 ArrayNode arrayNode = (ArrayNode) actualObj.get("fills");
 Assertions.assertThat(arrayNode.get(1).asBoolean()).isTrue();
}

代码示例来源:origin: twosigma/beakerx

@Test
public void serializeVisibleConstantLine_resultJsonHasVisible() throws IOException {
 //when
 ConstantLine constantLine = new ConstantLine();
 constantLine.setVisible(true);
 constantLineSerializer.serialize(constantLine, jgen, new DefaultSerializerProvider.Impl());
 jgen.flush();
 //then
 JsonNode actualObj = mapper.readTree(sw.toString());
 Assertions.assertThat(actualObj.has("visible")).isTrue();
 Assertions.assertThat(actualObj.get("visible").asBoolean()).isTrue();
}

代码示例来源:origin: twosigma/beakerx

@Test
public void serializeShowLabelConstantLine_resultJsonHasShowLabel() throws IOException {
 //when
 ConstantLine constantLine = new ConstantLine();
 constantLine.setShowLabel(true);
 constantLineSerializer.serialize(constantLine, jgen, new DefaultSerializerProvider.Impl());
 jgen.flush();
 //then
 JsonNode actualObj = mapper.readTree(sw.toString());
 Assertions.assertThat(actualObj.has("showLabel")).isTrue();
 Assertions.assertThat(actualObj.get("showLabel").asBoolean()).isTrue();
}

代码示例来源:origin: twosigma/beakerx

@Test
public void serializeFillCategoryPoints_resultJsonHasFill() throws IOException {
 //when
 CategoryPoints categoryPoints = new CategoryPoints();
 categoryPoints.setFill(true);
 categoryPointsSerializer.serialize(categoryPoints, jgen, new DefaultSerializerProvider.Impl());
 jgen.flush();
 //then
 JsonNode actualObj = mapper.readTree(sw.toString());
 Assertions.assertThat(actualObj.has("fill")).isTrue();
 Assertions.assertThat(actualObj.get("fill").asBoolean()).isTrue();
}

相关文章