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

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

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

JsonNode.floatValue介绍

[英]Returns 32-bit floating 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 means that an overflow is possible for long values
[中]返回此节点的32位浮点值,当且仅当此节点为数字时(#isNumber返回true)。对于其他类型,返回0.0。对于整数值,使用强制进行转换;这意味着“long”值可能会溢出

代码示例

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

return (D) Float.valueOf(jsonNode.floatValue());

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

return ValueReference.of(value.doubleValue());
} else if (valueType == ValueType.FLOAT && value.isFloat()) {
  return ValueReference.of(value.floatValue());
} else if (valueType == ValueType.INTEGER && value.isInt()) {
  return ValueReference.of(value.intValue());

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

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

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

@Test
public void testSuccessfulParseToContentWhenCEFContainsJSON() throws IOException {
  final TestRunner runner = TestRunners.newTestRunner(new ParseCEF());
  runner.setProperty(ParseCEF.FIELDS_DESTINATION, ParseCEF.DESTINATION_CONTENT);
  runner.enqueue(sample2.getBytes());
  runner.run();
  runner.assertAllFlowFilesTransferred(ParseCEF.REL_SUCCESS, 1);
  final MockFlowFile mff = runner.getFlowFilesForRelationship(ParseCEF.REL_SUCCESS).get(0);
  byte [] rawJson = mff.toByteArray();
  JsonNode results = new ObjectMapper().readTree(rawJson);
  JsonNode header = results.get("header");
  JsonNode extension = results.get("extension");
  Assert.assertEquals("TestVendor", header.get("deviceVendor").asText());
  Assert.assertEquals(sdf.format(new Date(1423441663000L)),
      extension.get("rt").asText());
  Assert.assertEquals("Test Long", extension.get("cn3Label").asText());
  Assert.assertEquals( 9223372036854775807L, extension.get("cn3").asLong());
  Assert.assertTrue(extension.get("cfp1").floatValue() == 1.234F);
  Assert.assertEquals("Test FP Number", extension.get("cfp1Label").asText());
  Assert.assertEquals("00:00:0c:07:ac:00", extension.get("smac").asText());
  Assert.assertEquals("2001:cdba:0:0:0:0:3257:9652", extension.get("c6a3").asText());
  Assert.assertEquals("Test IPv6", extension.get("c6a3Label").asText());
  Assert.assertEquals("Test String", extension.get("cs1Label").asText());
  Assert.assertEquals("test test test chocolate", extension.get("cs1").asText());
  Assert.assertEquals("123.123.123.123", extension.get("destinationTranslatedAddress").asText());
  JsonNode inner = new ObjectMapper().readTree(extension.get("cs2").asText());
  Assert.assertEquals("chocolate!", inner.get("test_test_test").asText());
}

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

@Test
public void testSuccessfulParseToContent() throws IOException {
  final TestRunner runner = TestRunners.newTestRunner(new ParseCEF());
  runner.setProperty(ParseCEF.FIELDS_DESTINATION, ParseCEF.DESTINATION_CONTENT);
  runner.enqueue(sample1.getBytes());
  runner.run();
  runner.assertAllFlowFilesTransferred(ParseCEF.REL_SUCCESS, 1);
  final MockFlowFile mff = runner.getFlowFilesForRelationship(ParseCEF.REL_SUCCESS).get(0);
  byte [] rawJson = mff.toByteArray();
  JsonNode results = new ObjectMapper().readTree(rawJson);
  JsonNode header = results.get("header");
  JsonNode extension = results.get("extension");
  Assert.assertEquals("TestVendor", header.get("deviceVendor").asText());
  Assert.assertEquals(sdf.format(new Date(1423441663000L)),
            extension.get("rt").asText());
  Assert.assertEquals("Test Long", extension.get("cn3Label").asText());
  Assert.assertEquals( 9223372036854775807L, extension.get("cn3").asLong());
  Assert.assertTrue(extension.get("cfp1").floatValue() == 1.234F);
  Assert.assertEquals("Test FP Number", extension.get("cfp1Label").asText());
  Assert.assertEquals("00:00:0c:07:ac:00", extension.get("smac").asText());
  Assert.assertEquals("2001:cdba:0:0:0:0:3257:9652", extension.get("c6a3").asText());
  Assert.assertEquals("Test IPv6", extension.get("c6a3Label").asText());
  Assert.assertEquals("123.123.123.123", extension.get("destinationTranslatedAddress").asText());
  Assert.assertEquals("Test String", extension.get("cs1Label").asText());
  Assert.assertEquals("test test test chocolate", extension.get("cs1").asText());
}

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

return (new LongWritable((value.longValue())));
case FLOAT:
 return (new FloatWritable(value.floatValue()));
case DOUBLE:
 return (new DoubleWritable(value.doubleValue()));

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

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

代码示例来源:origin: apache/james-project

@Override
public Optional<Float> deserialize(JsonNode json) {
  if (json instanceof FloatNode) {
    return Optional.of(json.floatValue());
  } else if (json instanceof DoubleNode) {
    return Optional.of(json.floatValue());
  } else {
    return Optional.empty();
  }
}

代码示例来源:origin: net.anotheria/ano-doc

@Override
  public FloatProperty deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonNode node = jp.getCodec().readTree(jp);
    String nameId = node.get("id").textValue();
    float value = node.get("value").floatValue();

    return new FloatProperty(nameId, value);
  }
}

代码示例来源:origin: org.graylog.jest/jest-common

public Float getMaxScore() {
  Float maxScore = null;
  JsonNode obj = getPath(PATH_TO_MAX_SCORE);
  if (obj != null) maxScore = obj.floatValue();
  return maxScore;
}

代码示例来源:origin: DigitalPebble/storm-crawler

@Override
public void configure(Map stormConf, JsonNode filterParams) {
  JsonNode node = filterParams.get("key");
  if (node != null && node.isTextual()) {
    mdKey = node.asText("lang");
  }
  node = filterParams.get("minProb");
  if (node != null && node.isNumber()) {
    minProb = node.floatValue();
  }
  node = filterParams.get("md.skip");
  if (node != null && node.isTextual()) {
    mdSkip = node.asText();
  }
}

代码示例来源:origin: com.atlassian.oai/swagger-request-validator-core

@Override
  public void validate(final ProcessingReport report,
             final MessageBundle bundle,
             final FullData data) throws ProcessingException {
    final JsonNode instance = data.getInstance().getNode();

    final float f = instance.floatValue();
    final String original = String.valueOf(instance.decimalValue());
    final String parsed = String.valueOf(f);

    if (!original.equals(parsed)) {
      report.warn(newMsg(data, bundle, "warn.format.float.overflow")
          .put("key", "warn.format.float.overflow")
          .putArgument("value", original)
          .putArgument("converted", parsed));
    }
  }
}

代码示例来源:origin: com.github.bjansen/swagger-schema-validator

@Override
  public void validate(final ProcessingReport report,
             final MessageBundle bundle,
             final FullData data) throws ProcessingException {
    final JsonNode instance = data.getInstance().getNode();

    final float f = instance.floatValue();
    final String original = String.valueOf(instance.decimalValue());
    final String parsed = String.valueOf(f);

    if (!original.equals(parsed)) {
      report.warn(newMsg(data, bundle, "warn.format.float.overflow")
        .put("key", "warn.format.float.overflow")
        .putArgument("value", original)
        .putArgument("converted", parsed));
    }
  }
}

代码示例来源:origin: cwensel/cascading

@Test
public void testCoerceArray() throws Exception
 {
 TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) );
 entry.setObject( 0, JSONData.nested );
 CopySpec copySpec = new CopySpec()
  .fromTransform( "/person", "/measures/*/value", JSONPrimitiveTransforms.TO_FLOAT );
 JSONCopyAsFunction function = new JSONCopyAsFunction( new Fields( "result" ), copySpec );
 TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) );
 Object value = result.iterator().next().getObject( 0 );
 assertNotNull( value );
 assertEquals( JsonNodeType.ARRAY, ( (ObjectNode) value ).get( "measures" ).getNodeType() );
 assertEquals( FloatNode.class, ( (ObjectNode) value ).get( "measures" ).get( 0 ).get( "value" ).getClass() );
 assertEquals( 1000.0F, ( (ObjectNode) value ).get( "measures" ).get( 0 ).get( "value" ).floatValue() );
 assertEquals( FloatNode.class, ( (ObjectNode) value ).get( "measures" ).get( 1 ).get( "value" ).getClass() );
 assertEquals( 2000.0F, ( (ObjectNode) value ).get( "measures" ).get( 1 ).get( "value" ).floatValue() );
 }

代码示例来源:origin: cascading/cascading-nested-json

@Test
public void testCoerceArray() throws Exception
 {
 TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) );
 entry.setObject( 0, JSONData.nested );
 CopySpec copySpec = new CopySpec()
  .fromTransform( "/person", "/measures/*/value", JSONPrimitiveTransforms.TO_FLOAT );
 JSONCopyAsFunction function = new JSONCopyAsFunction( new Fields( "result" ), copySpec );
 TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) );
 Object value = result.iterator().next().getObject( 0 );
 assertNotNull( value );
 assertEquals( JsonNodeType.ARRAY, ( (ObjectNode) value ).get( "measures" ).getNodeType() );
 assertEquals( FloatNode.class, ( (ObjectNode) value ).get( "measures" ).get( 0 ).get( "value" ).getClass() );
 assertEquals( 1000.0F, ( (ObjectNode) value ).get( "measures" ).get( 0 ).get( "value" ).floatValue() );
 assertEquals( FloatNode.class, ( (ObjectNode) value ).get( "measures" ).get( 1 ).get( "value" ).getClass() );
 assertEquals( 2000.0F, ( (ObjectNode) value ).get( "measures" ).get( 1 ).get( "value" ).floatValue() );
 }

代码示例来源:origin: cwensel/cascading

@Test
public void testCoerceZero() throws Exception
 {
 TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) );
 entry.setObject( 0, JSONData.nested );
 CopySpec copySpec = new CopySpec()
  .fromTransform( "/person/zero", "/zeroValue", JSONPrimitiveTransforms.TO_FLOAT );
 JSONCopyAsFunction function = new JSONCopyAsFunction( new Fields( "result" ), copySpec );
 TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) );
 Object value = result.iterator().next().getObject( 0 );
 assertNotNull( value );
 assertEquals( JsonNodeType.NUMBER, ( (ObjectNode) value ).get( "zeroValue" ).getNodeType() );
 assertEquals( FloatNode.class, ( (ObjectNode) value ).get( "zeroValue" ).getClass() );
 assertEquals( 0.0F, ( (ObjectNode) value ).get( "zeroValue" ).floatValue() );
 assertEquals( "0.0", ( (ObjectNode) value ).get( "zeroValue" ).asText() );
 }

代码示例来源:origin: cascading/cascading-nested-json

@Test
public void testCoerceZero() throws Exception
 {
 TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) );
 entry.setObject( 0, JSONData.nested );
 CopySpec copySpec = new CopySpec()
  .fromTransform( "/person/zero", "/zeroValue", JSONPrimitiveTransforms.TO_FLOAT );
 JSONCopyAsFunction function = new JSONCopyAsFunction( new Fields( "result" ), copySpec );
 TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) );
 Object value = result.iterator().next().getObject( 0 );
 assertNotNull( value );
 assertEquals( JsonNodeType.NUMBER, ( (ObjectNode) value ).get( "zeroValue" ).getNodeType() );
 assertEquals( FloatNode.class, ( (ObjectNode) value ).get( "zeroValue" ).getClass() );
 assertEquals( 0.0F, ( (ObjectNode) value ).get( "zeroValue" ).floatValue() );
 assertEquals( "0.0", ( (ObjectNode) value ).get( "zeroValue" ).asText() );
 }

代码示例来源:origin: cwensel/cascading

@Test
public void testCoerce() throws Exception
 {
 TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) );
 entry.setObject( 0, JSONData.nested );
 CopySpec copySpec = new CopySpec()
  .fromTransform( "/person/measure", "/value", JSONPrimitiveTransforms.TO_FLOAT );
 JSONCopyAsFunction function = new JSONCopyAsFunction( new Fields( "result" ), copySpec );
 TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) );
 Object value = result.iterator().next().getObject( 0 );
 assertNotNull( value );
 assertEquals( JsonNodeType.NUMBER, ( (ObjectNode) value ).get( "value" ).getNodeType() );
 assertEquals( FloatNode.class, ( (ObjectNode) value ).get( "value" ).getClass() );
 assertEquals( 100.0F, ( (ObjectNode) value ).get( "value" ).floatValue() );
 }

代码示例来源:origin: cwensel/cascading

@Test
public void testCoerce() throws Exception
 {
 Fields fields = new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "result", JSONCoercibleType.TYPE ) );
 TupleEntry entry = new TupleEntry( fields, Tuple.size( 2 ) );
 entry.setObject( 0, JSONData.nested );
 entry.setObject( 1, JSONData.simple );
 CopySpec copySpec = new CopySpec()
  .fromTransform( "/person/measure", "/value", JSONPrimitiveTransforms.TO_FLOAT );
 JSONCopyIntoFunction function = new JSONCopyIntoFunction( new Fields( "result" ), copySpec );
 TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) );
 Object value = result.iterator().next().getObject( 0 );
 assertNotNull( value );
 assertEquals( "value", ( (ObjectNode) value ).get( "existing" ).textValue() ); // confirm we put data into an existing object
 assertEquals( JsonNodeType.NUMBER, ( (ObjectNode) value ).get( "value" ).getNodeType() );
 assertEquals( FloatNode.class, ( (ObjectNode) value ).get( "value" ).getClass() );
 assertEquals( 100.0F, ( (ObjectNode) value ).get( "value" ).floatValue() );
 }

代码示例来源:origin: cascading/cascading-nested-json

@Test
public void testCoerce() throws Exception
 {
 TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) );
 entry.setObject( 0, JSONData.nested );
 CopySpec copySpec = new CopySpec()
  .fromTransform( "/person/measure", "/value", JSONPrimitiveTransforms.TO_FLOAT );
 JSONCopyAsFunction function = new JSONCopyAsFunction( new Fields( "result" ), copySpec );
 TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) );
 Object value = result.iterator().next().getObject( 0 );
 assertNotNull( value );
 assertEquals( JsonNodeType.NUMBER, ( (ObjectNode) value ).get( "value" ).getNodeType() );
 assertEquals( FloatNode.class, ( (ObjectNode) value ).get( "value" ).getClass() );
 assertEquals( 100.0F, ( (ObjectNode) value ).get( "value" ).floatValue() );
 }

相关文章