本文整理了Java中org.codehaus.jackson.JsonNode.get()
方法的一些代码示例,展示了JsonNode.get()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.get()
方法的具体详情如下:
包路径:org.codehaus.jackson.JsonNode
类名称:JsonNode
方法名:get
[英]Method for accessing value of the specified element of an array node. For other nodes, null is always returned.
For array nodes, index specifies exact location within array and allows for efficient iteration over child elements (underlying storage is guaranteed to be efficiently indexable, i.e. has random-access to elements). If index is less than 0, or equal-or-greater than node.size()
, null is returned; no exception is thrown for any index.
[中]用于访问数组节点的指定元素的值的方法。对于其他节点,总是返回null。
对于阵列节点,索引指定了阵列中的确切位置,并允许在子元素上进行有效迭代(保证底层存储可以有效地进行索引,即对元素进行随机访问)。如果索引小于0,或等于或大于node.size()
,则返回null;任何索引都不会引发异常。
代码示例来源:origin: neo4j/neo4j
private static JsonNode get( Iterable<JsonNode> jsonNodes, String id )
{
for ( JsonNode jsonNode : jsonNodes )
{
if ( id.equals( jsonNode.get( "id" ).getTextValue() ) )
{
return jsonNode;
}
}
return null;
}
}
代码示例来源:origin: neo4j/neo4j
private static void assertTypeEqual( String expectedType, HTTP.Response response ) throws JsonParseException
{
JsonNode data = response.get( "results" ).get( 0 ).get( "data" );
JsonNode meta = data.get( 0 ).get( "meta" );
assertEquals( 1, meta.size() );
assertEquals( expectedType, meta.get( 0 ).get( "type" ).asText() );
}
代码示例来源:origin: neo4j/neo4j
private static JsonNode extractSingleElement( HTTP.Response response ) throws JsonParseException
{
JsonNode data = response.get( "results" ).get( 0 ).get( "data" );
assertEquals( 1, data.size() );
JsonNode row = data.get( 0 ).get( "row" );
assertEquals( 1, row.size() );
return row.get( 0 );
}
代码示例来源:origin: neo4j/neo4j
private static JsonNode getSingle( JsonNode node, String key )
{
JsonNode data = node.get( key );
assertEquals( 1, data.size() );
return data.get( 0 );
}
}
代码示例来源:origin: neo4j/neo4j
private Set<String> identifiersOf( JsonNode root )
{
Set<String> parentIds = new HashSet<>();
for ( JsonNode id : root.get( "identifiers" ) )
{
parentIds.add( id.asText() );
}
return parentIds;
}
代码示例来源:origin: neo4j/neo4j
private static JsonNode getSingleData( HTTP.Response response ) throws JsonParseException
{
JsonNode data = response.get( "results" ).get( 0 ).get( "data" );
assertEquals( 1, data.size() );
return data.get( 0 );
}
代码示例来源:origin: neo4j/neo4j
private JsonNode findNamedBean( JsonNode beans, String beanName )
{
for ( JsonNode bean : beans )
{
JsonNode name = bean.get( "name" );
if ( name != null && name.asText().endsWith( ",name=" + beanName ) )
{
return bean;
}
}
throw new NoSuchElementException();
}
代码示例来源: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
private JsonNode assertIsPlanRoot( String result ) throws JsonParseException
{
JsonNode json = jsonNode( result );
JsonNode results = json.get( "results" ).get( 0 );
JsonNode plan = results.get( "plan" );
assertTrue( "Expected plan to be an object", plan != null && plan.isObject() );
JsonNode root = plan.get("root");
assertTrue("Expected plan to be an object", root != null && root.isObject());
return root;
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldIncludeCause() throws Exception
{
// Given
ExceptionRepresentation rep = new ExceptionRepresentation(
new RuntimeException( "Hoho", new RuntimeException( "Haha", new RuntimeException( "HAHA!" ) ) ) );
// When
JsonNode out = serialize( rep );
// Then
assertThat( out.get("cause").get("message").asText(), is( "Haha" ) );
assertThat( out.get( "cause" ).get("cause").get("message").asText(), is( "HAHA!") );
}
代码示例来源:origin: neo4j/neo4j
private void assertQueryGetsValue( ServerControls server, String query, long value ) throws Throwable
{
HTTP.Response response = HTTP.POST( server.httpURI().resolve( "db/data/transaction/commit" ).toString(),
quotedJson( "{ 'statements': [ { 'statement': '" + query + "' } ] }" ) );
assertEquals( "[]", response.get( "errors" ).toString() );
JsonNode result = response.get( "results" ).get( 0 );
assertEquals( "value", result.get( "columns" ).get( 0 ).asText() );
assertEquals( value, result.get( "data" ).get( 0 ).get( "row" ).get( 0 ).asLong() );
}
代码示例来源:origin: neo4j/neo4j
private void assertQueryGetsValue( ServerControls server, String query, long value ) throws Throwable
{
HTTP.Response response = HTTP.POST( server.httpURI().resolve( "db/data/transaction/commit" ).toString(),
quotedJson( "{ 'statements': [ { 'statement': '" + query + "' } ] }" ) );
assertEquals( "[]", response.get( "errors" ).toString() );
JsonNode result = response.get( "results" ).get( 0 );
assertEquals( "value", result.get( "columns" ).get( 0 ).asText() );
assertEquals( value, result.get( "data" ).get( 0 ).get( "row" ).get( 0 ).asLong() );
}
代码示例来源:origin: neo4j/neo4j
private static double[] coordinatesAsArray( JsonNode element )
{
return Iterables.stream( element.get( "coordinates" ) )
.mapToDouble( JsonNode::asDouble )
.toArray();
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldFixturesWork() throws Exception
{
// Given the rule in the beginning of this class
// When I run this test
// Then
HTTP.Response response = HTTP.POST( neo4j.httpURI().toString() + "db/data/transaction/commit",
quotedJson( "{'statements':[{'statement':'MATCH (n:User) RETURN n'}]}" ) );
assertThat( response.get( "results" ).get( 0 ).get( "data" ).size(), equalTo( 2 ) );
}
代码示例来源:origin: neo4j/neo4j
private static void assertNode( String id, JsonNode nodes, List<String> labels, Property... properties )
{
JsonNode node = get( nodes, id );
assertListEquals( "Node[" + id + "].labels", labels, node.get( "labels" ) );
JsonNode props = node.get( "properties" );
assertEquals( "length( Node[" + id + "].properties )", properties.length, props.size() );
for ( Property property : properties )
{
assertJsonEquals( "Node[" + id + "].properties[" + property.key() + "]",
property.value(), props.get( property.key() ) );
}
}
代码示例来源:origin: neo4j/neo4j
private void assertNodes( JsonNode result )
{
JsonNode nodes = result.get( "graph" ).get( "nodes" );
assertEquals( "there should be 3 nodes", 3, nodes.size() );
assertNode( "17", nodes, asList( "Foo" ), property( "name", "n1" ) );
assertNode( "666", nodes, Arrays.asList(), property( "name", "n2" ) );
assertNode( "42", nodes, asList( "Foo", "Bar" ), property( "name", "n3" ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldSayMalformedHeaderIfMalformedAuthorization() throws Exception
{
// Given
startServerWithConfiguredUser();
// When
HTTP.Response response = HTTP.withHeaders( HttpHeaders.AUTHORIZATION, "This makes no sense" ).GET( dataURL() );
// Then
assertThat( response.status(), equalTo( 400 ) );
assertThat( response.get( "errors" ).get( 0 ).get( "code" ).asText(), equalTo( "Neo.ClientError.Request.InvalidFormat" ) );
assertThat( response.get( "errors" ).get( 0 ).get( "message" ).asText(), equalTo( "Invalid authentication header." ) );
}
代码示例来源:origin: neo4j/neo4j
private void assertRelationships( JsonNode result )
{
JsonNode relationships = result.get( "graph" ).get( "relationships" );
assertEquals( "there should be 2 relationships", 2, relationships.size() );
assertRelationship( "7", relationships, "17", "ONE", "666", property( "name", "r1" ) );
assertRelationship( "8", relationships, "17", "TWO", "42", property( "name", "r2" ) );
}
代码示例来源:origin: neo4j/neo4j
private void assertTemporalEquals( JsonNode data, String value, String type )
{
JsonNode row = getSingle( data, "row" );
assertThat( row.asText(), equalTo( value ) );
JsonNode meta = getSingle( data, "meta" );
assertEquals( type, meta.get( "type" ).asText() );
}
内容来源于网络,如有侵权,请联系作者删除!