本文整理了Java中org.codehaus.jackson.JsonNode.getTextValue()
方法的一些代码示例,展示了JsonNode.getTextValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.getTextValue()
方法的具体详情如下:
包路径:org.codehaus.jackson.JsonNode
类名称:JsonNode
方法名:getTextValue
[英]Method to use for accessing String values. Does NOT do any conversions for non-String value nodes; for non-String values (ones for which #isTextual returns false) null will be returned. For String values, null is never returned (but empty Strings may be)
[中]用于访问字符串值的方法。不为非字符串值节点进行任何转换;对于非字符串值(即#isTextual返回false的值),将返回null。对于字符串值,永远不会返回null(但可能会返回空字符串)
代码示例来源:origin: org.apache.avro/avro
/** Extracts text value associated to key from the container JsonNode. */
private static String getOptionalText(JsonNode container, String key) {
JsonNode jsonNode = container.get(key);
return jsonNode != null ? jsonNode.getTextValue() : null;
}
代码示例来源:origin: org.apache.avro/avro
private String parseDocNode(JsonNode json) {
JsonNode nameNode = json.get("doc");
if (nameNode == null) return null; // no doc defined
return nameNode.getTextValue();
}
代码示例来源:origin: org.apache.avro/avro
/** Return the defined properties that have string values. */
@Deprecated public Map<String,String> getProps() {
Map<String,String> result = new LinkedHashMap<String,String>();
for (Map.Entry<String,JsonNode> e : props.entrySet())
if (e.getValue().isTextual())
result.put(e.getKey(), e.getValue().getTextValue());
return result;
}
代码示例来源:origin: org.apache.avro/avro
private void parseNamespace(JsonNode json) {
JsonNode nameNode = json.get("namespace");
if (nameNode == null) return; // no namespace defined
this.namespace = nameNode.getTextValue();
types.space(this.namespace);
}
代码示例来源:origin: org.apache.avro/avro
private void parseName(JsonNode json) {
JsonNode nameNode = json.get("protocol");
if (nameNode == null)
throw new SchemaParseException("No protocol name specified: "+json);
this.name = nameNode.getTextValue();
}
代码示例来源:origin: linkedin/parseq
private static String getTextField(final JsonNode node, final String fieldName) throws IOException {
return getField(node, fieldName).getTextValue();
}
代码示例来源: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: org.apache.avro/avro
/**
* Returns the value of the named, string-valued property in this schema.
* Returns <tt>null</tt> if there is no string-valued property with that name.
*/
public String getProp(String name) {
JsonNode value = getJsonProp(name);
return value != null && value.isTextual() ? value.getTextValue() : null;
}
代码示例来源:origin: org.apache.avro/avro
static Set<String> parseAliases(JsonNode node) {
JsonNode aliasesNode = node.get("aliases");
if (aliasesNode == null)
return null;
if (!aliasesNode.isArray())
throw new SchemaParseException("aliases not an array: "+node);
Set<String> aliases = new LinkedHashSet<String>();
for (JsonNode aliasNode : aliasesNode) {
if (!aliasNode.isTextual())
throw new SchemaParseException("alias not a string: "+aliasNode);
aliases.add(aliasNode.getTextValue());
}
return aliases;
}
代码示例来源:origin: apache/incubator-gobblin
@Test
public void testRecord() throws DataConversionException, IOException {
Iterable<String> records = converter.convertRecord(null, sampleRecord, state);
Iterator<String> recordIt = records.iterator();
ObjectMapper objectMapper = new ObjectMapper();
String record = recordIt.next();
Assert.assertFalse(recordIt.hasNext());
JsonNode parsedRecord = objectMapper.readValue(record, JsonNode.class);
Assert.assertEquals(parsedRecord.get("field1").getTextValue(), sampleRecord.get("field1").toString());
}
}
代码示例来源: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: apache/incubator-gobblin
@Test
public void testRecord() throws DataConversionException {
Iterable<RecordWithMetadata<JsonNode>> records = converter.convertRecord(null, sampleRecord, state);
RecordWithMetadata<JsonNode> node = records.iterator().next();
Assert.assertEquals(node.getMetadata().getGlobalMetadata().getContentType(), "test.name+json");
Assert.assertEquals(node.getRecord().get("field1").getTextValue(), sampleRecord.get("field1").toString());
}
}
代码示例来源: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
@Test
public void shouldProduceResultStreamWithLegacyRestFormatAndNestedMaps() throws Exception
{
// given
ByteArrayOutputStream output = new ByteArrayOutputStream();
ExecutionResultSerializer serializer = getSerializerWith( output, "http://base.uri/" );
// when
serializer.statementResult( mockExecutionResult(
// RETURN {one:{two:['wait for it...', {three: 'GO!'}]}}
map( "map", map("one", map( "two", asList("wait for it...", map("three", "GO!") ) ) ) )
), false, ResultDataContent.rest );
serializer.finish();
// then
String result = output.toString( UTF_8.name() );
JsonNode json = jsonNode(result);
Map<String, Integer> columns = new HashMap<>();
int col = 0;
JsonNode results = json.get( "results" ).get( 0 );
for ( JsonNode column : results.get( "columns" ) )
{
columns.put( column.getTextValue(), col++ );
}
JsonNode row = results.get( "data" ).get( 0 ).get( "rest" );
JsonNode jsonMap = row.get( columns.get( "map" ) );
assertEquals( "wait for it...", jsonMap.get( "one" ).get( "two" ).get( 0 ).asText() );
assertEquals( "GO!", jsonMap.get( "one" ).get( "two" ).get( 1 ).get( "three" ).asText() );
}
代码示例来源:origin: apache/incubator-gobblin
@Test
public void testSuccessWithBinary()
throws DataConversionException, IOException {
ObjectMapper objectMapper = new ObjectMapper();
byte[] record = "aaaa".getBytes(StandardCharsets.UTF_8);
Metadata md = new Metadata();
md.getGlobalMetadata().setContentType("application/binary");
RecordWithMetadataToEnvelopedRecordWithMetadata converter = new RecordWithMetadataToEnvelopedRecordWithMetadata();
Iterator<RecordWithMetadata<byte[]>> recordWithMetadataIterator =
converter.convertRecord("", new RecordWithMetadata<>(record, md), null).iterator();
RecordWithMetadata recordWithMetadata = recordWithMetadataIterator.next();
JsonNode parsedElement = objectMapper.readValue((byte[]) recordWithMetadata.getRecord(), JsonNode.class);
Assert.assertEquals(parsedElement.get("r").getTextValue(), "YWFhYQ==");
}
}
代码示例来源:origin: apache/incubator-gobblin
@Test
public void testSuccessWithInferredPrintableByteArray()
throws DataConversionException, IOException {
ObjectMapper objectMapper = new ObjectMapper();
byte[] record = "abrac\\adabra".getBytes(StandardCharsets.UTF_8);
Metadata md = new Metadata();
md.getGlobalMetadata().setContentType("application/binary");
md.getGlobalMetadata().addTransferEncoding("base64");
RecordWithMetadataToEnvelopedRecordWithMetadata converter = new RecordWithMetadataToEnvelopedRecordWithMetadata();
Iterator<RecordWithMetadata<byte[]>> recordWithMetadataIterator =
converter.convertRecord("", new RecordWithMetadata<>(record, md), null).iterator();
RecordWithMetadata recordWithMetadata = recordWithMetadataIterator.next();
JsonNode parsedElement = objectMapper.readValue((byte[]) recordWithMetadata.getRecord(), JsonNode.class);
Assert.assertEquals(parsedElement.get("r").getTextValue(), new String(record, StandardCharsets.UTF_8));
}
代码示例来源:origin: apache/incubator-gobblin
@Test
public void testSuccessWithString()
throws DataConversionException, IOException {
ObjectMapper objectMapper = new ObjectMapper();
String innerRecord = "abracadabra";
RecordWithMetadataToEnvelopedRecordWithMetadata converter = new RecordWithMetadataToEnvelopedRecordWithMetadata();
RecordWithMetadata<String> record = new RecordWithMetadata<>(innerRecord, new Metadata());
Iterator<RecordWithMetadata<byte[]>> recordWithMetadataIterator =
converter.convertRecord("", record, null).iterator();
RecordWithMetadata recordWithMetadata = recordWithMetadataIterator.next();
JsonNode parsedElement = objectMapper.readValue((byte[]) recordWithMetadata.getRecord(), JsonNode.class);
Assert.assertEquals(parsedElement.get("mId").getTextValue(), record.getMetadata().getGlobalMetadata().getId());
Assert.assertEquals(parsedElement.get("r").getTextValue(), innerRecord);
Assert
.assertEquals(recordWithMetadata.getMetadata().getGlobalMetadata().getContentType(), "lnkd+recordWithMetadata");
Assert.assertNull(recordWithMetadata.getMetadata().getGlobalMetadata().getInnerContentType());
}
代码示例来源:origin: neo4j/neo4j
for ( JsonNode node : nodes.get( 0 ).get( "labels" ) )
labels.add( node.getTextValue() );
代码示例来源:origin: neo4j/neo4j
private static void assertJsonEquals( String message, Object expected, JsonNode actual )
{
if ( expected == null )
{
assertTrue( message, actual == null || actual.isNull() );
}
else if ( expected instanceof String )
{
assertEquals( message, expected, actual.getTextValue() );
}
else if ( expected instanceof Number )
{
assertEquals( message, expected, actual.getNumberValue() );
}
else
{
fail( message + " - unexpected type - " + expected );
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldReturnCorrectStatusCodeOnDeadlock() throws Exception
{
// Given
try ( Transaction tx = graphdb().beginTx() )
{
graphdb().createNode( Label.label( "First" ) );
graphdb().createNode( Label.label( "Second" ) );
tx.success();
}
// When I lock node:First
HTTP.Response begin = http.POST( "db/data/transaction",
quotedJson( "{ 'statements': [ { 'statement': 'MATCH (n:First) SET n.prop=1' } ] }" ));
// and I lock node:Second, and wait for a lock on node:First in another transaction
otherThread.execute( writeToFirstAndSecond() );
// and I wait for those locks to be pending
assertTrue( secondNodeLocked.await( 10, TimeUnit.SECONDS ) );
Thread.sleep( 1000 );
// and I then try and lock node:Second in the first transaction
HTTP.Response deadlock = http.POST( begin.location(),
quotedJson( "{ 'statements': [ { 'statement': 'MATCH (n:Second) SET n.prop=1' } ] }" ));
// Then
assertThat( deadlock.get( "errors" ).get( 0 ).get( "code" ).getTextValue(),
equalTo( DeadlockDetected.code().serialize() ) );
}
内容来源于网络,如有侵权,请联系作者删除!