本文整理了Java中org.codehaus.jackson.JsonNode.asInt()
方法的一些代码示例,展示了JsonNode.asInt()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.asInt()
方法的具体详情如下:
包路径:org.codehaus.jackson.JsonNode
类名称:JsonNode
方法名:asInt
[英]Method that will try to convert value of this node to a Java int. Numbers are coerced using default Java rules; booleans convert to 0 (false) and 1 (true), and Strings are parsed using default Java language integer parsing rules.
If representation can not be converted to an int (including structured types like Objects and Arrays), default value of 0 will be returned; no exceptions are thrown.
[中]方法,该方法将尝试将此节点的值转换为Java int;布尔值转换为0(false)和1(true),字符串使用默认的Java语言整数解析规则进行解析。
如果表示不能转换为int(包括对象和数组等结构化类型),则返回默认值0;没有抛出异常。
代码示例来源:origin: org.codehaus.jackson/jackson-core-asl
/**
* Method that will try to convert value of this node to a Java <b>int</b>.
* Numbers are coerced using default Java rules; booleans convert to 0 (false)
* and 1 (true), and Strings are parsed using default Java language integer
* parsing rules.
*<p>
* If representation can not be converted to an int (including structured types
* like Objects and Arrays),
* default value of <b>0</b> will be returned; no exceptions are thrown.
*
* @since 1.9 (replaces <code>getValueAsInt</code>)
*/
public int asInt() {
return asInt(0);
}
代码示例来源:origin: org.codehaus.jackson/jackson-core-asl
/**
* Method that will try to convert value of this node to a Java <b>int</b>.
* Numbers are coerced using default Java rules; booleans convert to 0 (false)
* and 1 (true), and Strings are parsed using default Java language integer
* parsing rules.
*<p>
* If representation can not be converted to an int (including structured types
* like Objects and Arrays),
* default value of <b>0</b> will be returned; no exceptions are thrown.
*
* @since 1.6
*
* @deprecated Since 1.9, use {@link #asInt} instead
*/
@Deprecated
public int getValueAsInt() { return asInt(0); }
代码示例来源:origin: org.codehaus.jackson/jackson-core-asl
/**
* Method that will try to convert value of this node to a Java <b>int</b>.
* Numbers are coerced using default Java rules; booleans convert to 0 (false)
* and 1 (true), and Strings are parsed using default Java language integer
* parsing rules.
*<p>
* If representation can not be converted to an int (including structured types
* like Objects and Arrays),
* specified <b>defaultValue</b> will be returned; no exceptions are thrown.
*
* @since 1.6
*
* @deprecated Since 1.9, use {@link #asInt} instead
*/
@Deprecated
public int getValueAsInt(int defaultValue) { return asInt(defaultValue); }
代码示例来源:origin: soabase/exhibitor
@Override
public int getInt(IntConfigs config)
{
JsonNode node = tree.get(fixName(config));
if ( node == null )
{
return 0;
}
return node.asInt();
}
};
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldWriteNestedMaps() throws Exception
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
JsonGenerator json = new JsonFactory( new Neo4jJsonCodec() ).createJsonGenerator( out );
JsonNode row = serialize( out, json, new RowWriter( ) );
MatcherAssert.assertThat( row.size(), equalTo( 1 ) );
JsonNode firstCell = row.get( 0 );
MatcherAssert.assertThat( firstCell.get( "one" ).get( "two" ).size(), is( 2 ) );
MatcherAssert.assertThat( firstCell.get( "one" ).get( "two" ).get( 0 ).asBoolean(), is( true ) );
MatcherAssert.assertThat( firstCell.get( "one" ).get( "two" ).get( 1 ).get( "three" ).asInt(), is( 42 ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldWriteNestedMaps() throws Exception
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
JsonGenerator json = new JsonFactory( new Neo4jJsonCodec() ).createJsonGenerator( out );
JsonNode rest = serialize( out, json, new RestRepresentationWriter( URI.create( "localhost" ) ) );
MatcherAssert.assertThat( rest.size(), equalTo( 1 ) );
JsonNode firstCell = rest.get( 0 );
MatcherAssert.assertThat( firstCell.get( "one" ).get( "two" ).size(), is( 2 ) );
MatcherAssert.assertThat( firstCell.get( "one" ).get( "two" ).get( 0 ).asBoolean(), is( true ) );
MatcherAssert.assertThat( firstCell.get( "one" ).get( "two" ).get( 1 ).get( "three" ).asInt(), is( 42 ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldSerializeMapsCorrectlyInRowsFormat() throws Exception
{
Response response = http.POST( "db/data/transaction/commit", quotedJson(
"{ 'statements': [ { 'statement': 'RETURN {one:{two:[true, {three: 42}]}}' } ] }" ) );
// then
assertThat( response.status(), equalTo( 200 ) );
JsonNode data = response.get( "results" ).get( 0 );
JsonNode row = data.get( "data" ).get( 0 ).get( "row" );
assertThat( row.size(), equalTo( 1 ) );
JsonNode firstCell = row.get( 0 );
assertThat( firstCell.get( "one" ).get( "two" ).size(), is( 2 ) );
assertThat( firstCell.get( "one" ).get( "two" ).get( 0 ).asBoolean(), is( true ) );
assertThat( firstCell.get( "one" ).get( "two" ).get( 1 ).get( "three" ).asInt(), is( 42 ) );
assertThat( response.get( "errors" ).size(), equalTo( 0 ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldHandleMapParametersCorrectly() throws Exception
{
Response response = http.POST(
"db/data/transaction/commit",
quotedJson("{ 'statements': [ { 'statement': " +
"'WITH {map} AS map RETURN map[0]', 'parameters':{'map':[{'index':0,'name':'a'},{'index':1,'name':'b'}]} } ] }"));
// then
assertThat( response.status(), equalTo( 200 ) );
JsonNode data = response.get( "results" ).get( 0 );
JsonNode row = data.get( "data" ).get( 0 ).get( "row" );
assertThat( row.size(), equalTo( 1 ) );
assertThat( row.get(0).get("index").asInt(), equalTo( 0 ) );
assertThat( row.get(0).get("name").asText(), equalTo( "a" ) );
assertThat( response.get( "errors" ).size(), equalTo( 0 ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldSerializeMapsCorrectlyInRestFormat() throws Exception
{
Response response = http.POST( "db/data/transaction/commit", quotedJson( "{ 'statements': [ { 'statement': " +
"'RETURN {one:{two:[true, {three: " +
"42}]}}', " +
"'resultDataContents':['rest'] } ] " +
"}" ) );
// then
assertThat( response.status(), equalTo( 200 ) );
JsonNode data = response.get( "results" ).get( 0 );
JsonNode rest = data.get( "data" ).get( 0 ).get( "rest" );
assertThat( rest.size(), equalTo( 1 ) );
JsonNode firstCell = rest.get( 0 );
assertThat( firstCell.get( "one" ).get( "two" ).size(), is( 2 ) );
assertThat( firstCell.get( "one" ).get( "two" ).get( 0 ).asBoolean(), is( true ) );
assertThat( firstCell.get( "one" ).get( "two" ).get( 1 ).get( "three" ).asInt(), is( 42 ) );
assertThat( response.get( "errors" ).size(), equalTo( 0 ) );
}
代码示例来源:origin: azkaban/azkaban
} else if (node.isNumber()) {
if (node.isInt()) {
return node.asInt();
} else if (node.isLong()) {
return node.asLong();
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldLaunchWithDeclaredProcedures() throws Exception
{
// When
try ( ServerControls server = createServer( MyProcedures.class ).newServer() )
{
// Then
HTTP.Response response = HTTP.POST( server.httpURI().resolve( "db/data/transaction/commit" ).toString(),
quotedJson( "{ 'statements': [ { 'statement': 'CALL org.neo4j.harness.myProc' } ] }" ) );
JsonNode result = response.get( "results" ).get( 0 );
assertEquals( "someNumber", result.get( "columns" ).get( 0 ).asText() );
assertEquals( 1337, result.get( "data" ).get( 0 ).get( "row" ).get( 0 ).asInt() );
assertEquals( "[]", response.get( "errors" ).toString() );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldLaunchWithDeclaredFunctions() throws Exception
{
// When
try ( ServerControls server = createServer( MyFunctions.class ).newServer() )
{
// Then
HTTP.Response response = HTTP.POST( server.httpURI().resolve( "db/data/transaction/commit" ).toString(),
quotedJson(
"{ 'statements': [ { 'statement': 'RETURN org.neo4j.harness.myFunc() AS someNumber' } ] " +
"}" ) );
JsonNode result = response.get( "results" ).get( 0 );
assertEquals( "someNumber", result.get( "columns" ).get( 0 ).asText() );
assertEquals( 1337, result.get( "data" ).get( 0 ).get( "row" ).get( 0 ).asInt() );
assertEquals( "[]", response.get( "errors" ).toString() );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldLaunchWithDeclaredFunctions() throws Exception
{
// When
Class<MyFunctions> functionClass = MyFunctions.class;
try ( ServerControls server = createServer( functionClass ).newServer() )
{
// Then
HTTP.Response response = HTTP.POST( server.httpURI().resolve( "db/data/transaction/commit" ).toString(),
quotedJson(
"{ 'statements': [ { 'statement': 'RETURN org.neo4j.harness.myFunc() AS someNumber' } ] " +
"}" ) );
JsonNode result = response.get( "results" ).get( 0 );
assertEquals( "someNumber", result.get( "columns" ).get( 0 ).asText() );
assertEquals( 1337, result.get( "data" ).get( 0 ).get( "row" ).get( 0 ).asInt() );
assertEquals( "[]", response.get( "errors" ).toString() );
}
}
代码示例来源:origin: apache/hive
scale = fileSchema.getJsonProp(AvroSerDe.AVRO_PROP_SCALE).asInt();
} catch(Exception ex) {
throw new AvroSerdeException("Failed to obtain scale value from file schema: " + fileSchema, ex);
代码示例来源:origin: soabase/exhibitor
int code = value.get("state").asInt();
String description = value.get("description").getTextValue();
return new ServerStatus(spec.getHostname(), code, description, value.get("isLeader").getBooleanValue());
代码示例来源:origin: apache/hive
assertTrue(jsonTree.isObject());
assertEquals("test_rp_2", jsonTree.get("name").asText());
assertEquals(10, jsonTree.get("parallelism").asInt());
assertEquals("def", jsonTree.get("defaultPool").asText());
assertTrue(jsonTree.get("pools").isArray());
assertEquals("pool2", pool2.get("name").asText());
assertEquals("fcfs", pool2.get("schedulingPolicy").asText());
assertEquals(7, pool2.get("parallelism").asInt());
assertEquals(0.7, pool2.get("allocFraction").asDouble(), 0.00001);
assertTrue(pool2.get("triggers").isArray());
assertEquals("pool1", pool1.get("name").asText());
assertEquals("fair", pool1.get("schedulingPolicy").asText());
assertEquals(3, pool1.get("parallelism").asInt());
assertEquals(0.3, pool1.get("allocFraction").asDouble(), 0.00001);
assertTrue(pool1.get("triggers").isArray());
代码示例来源:origin: neo4j/neo4j
assertEquals( "child", child.get( "operatorType" ).getTextValue() );
identifiers.add( identifiersOf( child ) );
childIds.add( child.get( "id" ).asInt() );
代码示例来源:origin: neo4j/neo4j
@Documented( "Get the degree of a node\n" +
"\n" +
"Return the total number of relationships associated with a node." )
@Test
@GraphDescription.Graph( {"Root knows Mattias", "Root knows Johan"} )
public void get_degree() throws JsonParseException
{
Map<String,Node> nodes = data.get();
String nodeUri = getNodeUri( nodes.get( "Root" ) );
// Document
RESTRequestGenerator.ResponseEntity response = gen.get()
.expectedStatus( 200 )
.get( nodeUri + "/degree/all" );
// Then
assertEquals( 2, JsonHelper.jsonNode( response.response().getEntity() ).asInt() );
}
代码示例来源:origin: neo4j/neo4j
@Documented( "Get the degree of a node by direction\n" +
"\n" +
"Return the number of relationships of a particular direction for a node.\n" +
"Specify `all`, `in` or `out`." )
@Test
@GraphDescription.Graph( {"Root knows Mattias", "Root knows Johan"} )
public void get_degree_by_direction() throws JsonParseException
{
Map<String,Node> nodes = data.get();
String nodeUri = getNodeUri( nodes.get( "Root" ) );
// Document
RESTRequestGenerator.ResponseEntity response = gen.get()
.expectedStatus( 200 )
.get( nodeUri + "/degree/out" );
// Then
assertEquals( 2, JsonHelper.jsonNode( response.response().getEntity() ).asInt() );
}
代码示例来源:origin: neo4j/neo4j
@Documented( "Get the degree of a node by direction and types\n" +
"\n" +
"If you are only interested in the degree of a particular relationship type, or a set of " +
"relationship types, you specify relationship types after the direction.\n" +
"You can combine multiple relationship types by using the `&` character." )
@Test
@GraphDescription.Graph( {"Root KNOWS Mattias", "Root KNOWS Johan", "Root LIKES Cookie"} )
public void get_degree_by_direction_and_type() throws JsonParseException
{
Map<String,Node> nodes = data.get();
String nodeUri = getNodeUri( nodes.get( "Root" ) );
// Document
RESTRequestGenerator.ResponseEntity response = gen.get()
.expectedStatus( 200 )
.get( nodeUri + "/degree/out/KNOWS&LIKES" );
// Then
assertEquals( 3, JsonHelper.jsonNode( response.response().getEntity() ).asInt() );
}
}
内容来源于网络,如有侵权,请联系作者删除!