org.codehaus.jackson.JsonNode.size()方法的使用及代码示例

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

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

JsonNode.size介绍

[英]Method that returns number of child nodes this node contains: for Array nodes, number of child elements, for Object nodes, number of fields, and for all other nodes 0.
[中]方法返回此节点包含的子节点数:对于数组节点,子元素数,对象节点,字段数,以及所有其他节点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 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 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

@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

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

@Test
public void should_serialize_collect_correctly() throws Exception
{
  // given
  http.POST( "db/data/transaction/commit", singleStatement( "CREATE (n:Foo)" ) );
  // when
  Response response = http.POST( "db/data/transaction/commit", quotedJson(
      "{ 'statements': [ { 'statement': 'MATCH (n:Foo) RETURN COLLECT(n)' } ] }" ) );
  // then
  assertThat( response.status(), equalTo( 200 ) );
  JsonNode data = response.get( "results" ).get( 0 );
  assertThat( data.get( "columns" ).get( 0 ).asText(), equalTo( "COLLECT(n)" ) );
  assertThat( data.get( "data" ).get( 0 ).get( "row" ).size(), equalTo( 1 ) );
  assertThat( data.get( "data" ).get( 0 ).get( "row" ).get( 0 ).get( 0 ).size(), equalTo( 0 ) );
  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 shouldExtractNodesFromRow() throws Exception
{
  // given
  Map<String, Object> row = new HashMap<>();
  row.put( "n1", n1 );
  row.put( "n2", n2 );
  row.put( "n3", n3 );
  row.put( "other.thing", "hello" );
  row.put( "some.junk", 0x0099cc );
  // when
  JsonNode result = write( row );
  // then
  assertNodes( result );
  assertEquals( "there should be no relationships", 0, result.get( "graph" ).get( "relationships" ).size() );
}

代码示例来源: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 assertListEquals( String what, List<String> expected, JsonNode jsonNode )
{
  assertTrue( what + " - should be a list", jsonNode.isArray() );
  List<String> actual = new ArrayList<>( jsonNode.size() );
  for ( JsonNode node : jsonNode )
  {
    actual.add( node.getTextValue() );
  }
  assertEquals( what, expected, actual );
}

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

@Test
public void shouldWorkWhenHittingTheASTCacheInCypher() throws JsonParseException
{
  // give a cached plan
  Response response = http.POST( "db/data/transaction/commit",
      singleStatement( "MATCH (group:Group {name: \\\"AAA\\\"}) RETURN *" ) );
  assertThat( response.status(), equalTo( 200 ) );
  assertThat( response.get( "errors" ).size(), equalTo( 0 ) );
  // when we hit the ast cache
  response = http.POST( "db/data/transaction/commit",
      singleStatement( "MATCH (group:Group {name: \\\"BBB\\\"}) RETURN *" ) );
  // then no errors (in particular no NPE)
  assertThat( response.status(), equalTo( 200 ) );
  assertThat( response.get( "errors" ).size(), equalTo( 0 ) );
}

代码示例来源: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

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 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

@Test
public void shouldHandleStringFixtures() throws Exception
{
  // Given two files in the root folder
  File targetFolder = testDir.directory();
  // When
  try ( ServerControls server = getServerBuilder( targetFolder )
      .withFixture( "CREATE (a:User)" )
      .newServer() )
  {
    // Then
    HTTP.Response response = HTTP.POST( server.httpURI().toString() + "db/data/transaction/commit",
        quotedJson( "{'statements':[{'statement':'MATCH (n:User) RETURN n'}]}" ) );
    assertThat( response.get( "results" ).get(0).get("data").size(), equalTo(1));
  }
}

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

@Test
public void shouldIgnoreEmptyFixtureFiles() throws Exception
{
  // Given two files in the root folder
  File targetFolder = testDir.directory();
  FileUtils.writeToFile( new File( targetFolder, "fixture1.cyp" ), "CREATE (u:User)\n" + "CREATE (a:OtherUser)",
      false );
  FileUtils.writeToFile( new File( targetFolder, "fixture2.cyp" ), "", false );
  // When
  try ( ServerControls server = getServerBuilder( targetFolder )
      .withFixture( targetFolder ).newServer() )
  {
    // Then
    HTTP.Response response = HTTP.POST( server.httpURI().toString() + "db/data/transaction/commit",
        quotedJson( "{'statements':[{'statement':'MATCH (n:User) RETURN n'}]}" ) );
    assertThat( response.get( "results" ).get(0).get("data").size(), equalTo(1));
  }
}

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

private static void assertRelationship( String id, JsonNode relationships, String startNodeId, String type,
                    String endNodeId, Property... properties )
{
  JsonNode relationship = get( relationships, id );
  assertEquals( "Relationship[" + id + "].labels", type, relationship.get( "type" ).getTextValue() );
  assertEquals( "Relationship[" + id + "].startNode", startNodeId,
         relationship.get( "startNode" ).getTextValue() );
  assertEquals( "Relationship[" + id + "].endNode", endNodeId, relationship.get( "endNode" ).getTextValue() );
  JsonNode props = relationship.get( "properties" );
  assertEquals( "length( Relationship[" + id + "].properties )", properties.length, props.size() );
  for ( Property property : properties )
  {
    assertJsonEquals( "Relationship[" + id + "].properties[" + property.key() + "]",
             property.value(), props.get( property.key() ) );
  }
}

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

public static void assertNoErrors( HTTP.Response response ) throws JsonParseException
  {
    assertEquals( "[]", response.get( "errors" ).toString() );
    assertEquals( 0, response.get( "errors" ).size() );
  }
}

相关文章