本文整理了Java中org.codehaus.jackson.JsonNode.asBoolean()
方法的一些代码示例,展示了JsonNode.asBoolean()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.asBoolean()
方法的具体详情如下:
包路径:org.codehaus.jackson.JsonNode
类名称: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 can not 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: org.codehaus.jackson/jackson-core-asl
/**
* 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 can not 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.
*
* @since 1.9 (replaces <code>getValueAsBoolean</code>)
*/
public boolean asBoolean() {
return asBoolean(false);
}
代码示例来源:origin: org.codehaus.jackson/jackson-core-asl
/**
* 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 can not be converted to a boolean value (including structured types
* like Objects and Arrays),
* specified <b>defaultValue</b> will be returned; no exceptions are thrown.
*
* @since 1.7
*
* @deprecated Since 1.9, use {@link #asBoolean} instead
*/
@Deprecated
public boolean getValueAsBoolean(boolean defaultValue) { return asBoolean(defaultValue); }
代码示例来源:origin: org.codehaus.jackson/jackson-core-asl
/**
* 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 can not 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.
*
* @since 1.7
*
* @deprecated Since 1.9, use {@link #asBoolean} instead
*/
@Deprecated
public boolean getValueAsBoolean() { return asBoolean(false); }
代码示例来源:origin: neo4j/neo4j
@Override
protected boolean matchesSafely( HTTP.Response response )
{
try
{
JsonNode list = TransactionMatchers.getJsonNodeWithName( response, "rest" ).iterator().next();
assertThat( list.get( 0 ).get( "metadata" ).get( "deleted" ).asBoolean(), equalTo( Boolean.TRUE ) );
assertThat( list.get( 1 ).get( "someKey" ).get( "metadata" ).get( "deleted" ).asBoolean(),
equalTo( Boolean.TRUE ) );
return true;
}
catch ( JsonParseException e )
{
return false;
}
}
代码示例来源:origin: kaaproject/kaa
private boolean isAddressableValue(Schema value) {
if (value.getType().equals(Type.RECORD)) {
if (value.getJsonProp(ADDRESSABLE_NAME) != null
&& !value.getFullName().equals(rootSchemaName)) {
return value.getJsonProp(ADDRESSABLE_NAME).asBoolean();
}
return true;
}
return false;
}
代码示例来源: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 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
@Override
protected boolean matchesSafely( HTTP.Response response )
{
try
{
for ( JsonNode node : getJsonNodeWithName( response, "meta" ) )
{
assertFalse( node.get( "deleted" ).asBoolean() );
}
return true;
}
catch ( JsonParseException e )
{
return false;
}
}
代码示例来源: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
@Override
protected boolean matchesSafely( HTTP.Response response )
{
try
{
Iterator<JsonNode> relationships = getJsonNodeWithName( response, "graph" ).get( "relationships" ).iterator();
for ( int i = 0; i < amount; ++i )
{
assertTrue( relationships.hasNext() );
JsonNode node = relationships.next();
assertThat( node.get( "deleted" ).asBoolean(), equalTo( Boolean.TRUE ) );
}
if ( relationships.hasNext() )
{
JsonNode node = relationships.next();
fail( "Expected no more nodes, but got a node with id " + node.get( "id" ) );
}
return true;
}
catch ( JsonParseException e )
{
return false;
}
}
代码示例来源: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: kaaproject/kaa
@Override
protected void customizeType(Record record, Schema fieldTypeSchema) {
if (record != null && record.getSchema().getName().equals(RECORD_FIELD_TYPE)) {
JsonNode addressableNode = fieldTypeSchema.getJsonProp(ADDRESSABLE);
if (addressableNode != null && addressableNode.isBoolean()) {
record.put(ADDRESSABLE, addressableNode.asBoolean());
} else {
record.put(ADDRESSABLE, true);
}
}
}
代码示例来源:origin: neo4j/neo4j
@Override
protected boolean matchesSafely( HTTP.Response response )
{
try
{
Iterator<JsonNode> entities = getJsonNodeWithName( response, "rest" ).iterator();
for ( int i = 0; i < amount; ++i )
{
assertTrue( entities.hasNext() );
JsonNode node = entities.next();
assertThat( node.get( "metadata" ).get( "deleted" ).asBoolean(), equalTo( Boolean.TRUE ) );
}
if ( entities.hasNext() )
{
fail( "Expected no more entities" );
}
return true;
}
catch ( JsonParseException e )
{
return false;
}
}
代码示例来源:origin: neo4j/neo4j
@Override
protected boolean matchesSafely( HTTP.Response response )
{
try
{
Iterator<JsonNode> nodes = getJsonNodeWithName( response, "graph" ).get( "nodes" ).iterator();
int deleted = 0;
while ( nodes.hasNext() )
{
JsonNode node = nodes.next();
if ( node.get( "deleted" ) != null )
{
assertTrue( node.get( "deleted" ).asBoolean() );
deleted++;
}
}
assertEquals( format( "Expected to see %d deleted elements but %d was encountered.", amount, deleted ),
amount, deleted );
return true;
}
catch ( JsonParseException e )
{
return false;
}
}
代码示例来源:origin: azkaban/azkaban
return node.asBoolean();
} else {
return null;
代码示例来源:origin: neo4j/neo4j
assertThat( node.get( "deleted" ).asBoolean(), equalTo( Boolean.TRUE ) );
String type = node.get( "type" ).getTextValue();
switch ( type )
assertThat( node.get( "deleted" ).asBoolean(), equalTo( Boolean.FALSE ) );
代码示例来源:origin: neo4j/neo4j
if ( inner.get( "deleted" ).asBoolean() )
if ( inner.get( "deleted" ).asBoolean() )
代码示例来源:origin: neo4j/neo4j
@Test
@Documented( "User status\n" +
"\n" +
"Given that you know the current password, you can ask the server for the user status." )
public void user_status() throws JsonParseException, IOException
{
// Given
startServerWithConfiguredUser();
// Document
RESTRequestGenerator.ResponseEntity response = gen.get()
.expectedStatus( 200 )
.withHeader( HttpHeaders.AUTHORIZATION, HTTP.basicAuthHeader( "neo4j", "secret" ) )
.get( userURL( "neo4j" ) );
// Then
JsonNode data = JsonHelper.jsonNode( response.entity() );
assertThat( data.get( "username" ).asText(), equalTo( "neo4j" ) );
assertThat( data.get( "password_change_required" ).asBoolean(), equalTo( false ) );
assertThat( data.get( "password_change" ).asText(), equalTo( passwordURL( "neo4j" ) ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
@Documented( "User status on first access\n" +
"\n" +
"On first access, and using the default password, the user status will indicate " +
"that the users password requires changing." )
public void user_status_first_access() throws JsonParseException, IOException
{
// Given
startServer( true );
// Document
RESTRequestGenerator.ResponseEntity response = gen.get()
.expectedStatus( 200 )
.withHeader( HttpHeaders.AUTHORIZATION, HTTP.basicAuthHeader( "neo4j", "neo4j" ) )
.get( userURL( "neo4j" ) );
// Then
JsonNode data = JsonHelper.jsonNode( response.entity() );
assertThat( data.get( "username" ).asText(), equalTo( "neo4j" ) );
assertThat( data.get( "password_change_required" ).asBoolean(), equalTo( true ) );
assertThat( data.get( "password_change" ).asText(), equalTo( passwordURL( "neo4j" ) ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
@Documented( "Authenticate to access the server\n" +
"\n" +
"Authenticate by sending a username and a password to Neo4j using HTTP Basic Auth.\n" +
"Requests should include an +Authorization+ header, with a value of +Basic <payload>+,\n" +
"where \"payload\" is a base64 encoded string of \"username:password\"." )
public void successful_authentication() throws JsonParseException, IOException
{
// Given
startServerWithConfiguredUser();
// Document
RESTRequestGenerator.ResponseEntity response = gen.get()
.expectedStatus( 200 )
.withHeader( HttpHeaders.AUTHORIZATION, HTTP.basicAuthHeader( "neo4j", "secret" ) )
.get( userURL( "neo4j" ) );
// Then
JsonNode data = JsonHelper.jsonNode( response.entity() );
assertThat( data.get( "username" ).asText(), equalTo( "neo4j" ) );
assertThat( data.get( "password_change_required" ).asBoolean(), equalTo( false ) );
assertThat( data.get( "password_change" ).asText(), equalTo( passwordURL( "neo4j" ) ) );
}
内容来源于网络,如有侵权,请联系作者删除!