本文整理了Java中com.fasterxml.jackson.databind.node.ObjectNode.findValue()
方法的一些代码示例,展示了ObjectNode.findValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ObjectNode.findValue()
方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.node.ObjectNode
类名称:ObjectNode
方法名:findValue
暂无
代码示例来源:origin: stackoverflow.com
public class MoneyDeserializer extends JsonDeserializer<Money> {
@Override
public Money deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
String currencyCode = "GBP";
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
ObjectNode root = mapper.readTree(jp);
DoubleNode amountNode = (DoubleNode) root.findValue("amount");
String amount = null;
if (null != amountNode) {
amount = amountNode.asText();
}
JsonNode currencyUnitNode = root.get("currencyUnit");
JsonNode currencyCodeNode = currencyUnitNode.get("currencyCode");
currencyCode = currencyCodeNode.textValue();
if (StringUtils.isBlank(amount) || StringUtils.isBlank(currencyCode)) {
throw new IOException("unable to parse json");
}
return Money.parse(currencyCode + " " + amount);
}}
代码示例来源:origin: alien4cloud/alien4cloud-cloudify-events-model
@Override
public AlienEvent deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
ObjectNode root = mapper.readTree(jp);
Class<? extends AlienEvent> eventClass = null;
String type = EventType.INSTANCE_STATE;
if (root.hasNonNull(TYPE_FIELD)) {
type = root.findValue(TYPE_FIELD).asText();
}
eventClass = registry.get(type);
if (eventClass == null) {
return null;
}
return mapper.readValue(jp, eventClass);
}
}
代码示例来源:origin: usdot-jpo-ode/jpo-ode
public static OdeBsmData createOdeBsmData(String consumedData) throws XmlUtilsException
{
ObjectNode consumed = XmlUtils.toObjectNode(consumedData);
JsonNode metadataNode = consumed.findValue(AppContext.METADATA_STRING);
if (metadataNode instanceof ObjectNode) {
ObjectNode object = (ObjectNode) metadataNode;
object.remove(AppContext.ENCODINGS_STRING);
}
OdeBsmMetadata metadata = (OdeBsmMetadata) JsonUtils.fromJson(
metadataNode.toString(), OdeBsmMetadata.class);
/*
* ODE-755 and ODE-765 Starting with schemaVersion=5 receivedMessageDetails
* will be present in BSM metadata. None should be present in prior versions.
*/
if (metadata.getSchemaVersion() <= 4) {
metadata.setReceivedMessageDetails(null);
}
OdeBsmPayload payload = new OdeBsmPayload(
BsmBuilder.genericBsm(consumed.findValue("BasicSafetyMessage")));
return new OdeBsmData(metadata, payload );
}
}
代码示例来源:origin: org.apache.james/james-server-jmap
@Test
public void processShouldWorkWhenKnownMethod() throws Exception {
ObjectNode parameters = new ObjectNode(new JsonNodeFactory(false));
parameters.put("id", "testId");
parameters.put("name", "testName");
JsonNode[] nodes = new JsonNode[] { new ObjectNode(new JsonNodeFactory(false)).textNode("getTestMethod"),
parameters,
new ObjectNode(new JsonNodeFactory(false)).textNode("#1")};
List<ProtocolResponse> responses = testee.handle(AuthenticatedProtocolRequest.decorate(ProtocolRequest.deserialize(nodes), mockHttpServletRequest))
.collect(Collectors.toList());
assertThat(responses).hasSize(1)
.extracting(
x -> x.getResults().findValue("id").asText(),
x -> x.getResults().findValue("name").asText(),
x -> x.getResults().findValue("message").asText())
.containsExactly(tuple("testId", "testName", "works"));
}
}
代码示例来源:origin: cwensel/cascading
@Test
public void testCopyExclude() throws Exception
{
Fields fields = new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "result", JSONCoercibleType.TYPE ) );
TupleEntry entry = new TupleEntry( fields, Tuple.size( 2 ) );
entry.setObject( 0, JSONData.nested );
entry.setObject( 1, JSONData.simple );
CopySpec copySpec = new CopySpec()
.exclude( "/person/ssn", "/person/children" );
JSONCopyIntoFunction function = new JSONCopyIntoFunction( new Fields( "result" ), copySpec );
TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) );
Object value = result.iterator().next().getObject( 0 );
assertNotNull( value );
assertEquals( "value", ( (ObjectNode) value ).get( "existing" ).textValue() ); // confirm we put data into an existing object
assertEquals( "John Doe", ( (ObjectNode) value ).findPath( "name" ).textValue() );
assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() );
assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) );
assertEquals( null, ( (ObjectNode) value ).findValue( "children" ) );
}
代码示例来源:origin: cwensel/cascading
@Test
public void testCopyExclude() throws Exception
{
TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) );
entry.setObject( 0, JSONData.nested );
CopySpec copySpec = new CopySpec()
.exclude( "/person/ssn", "/person/children" );
JSONCopyAsFunction function = new JSONCopyAsFunction( new Fields( "result" ), copySpec );
TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) );
Object value = result.iterator().next().getObject( 0 );
assertNotNull( value );
assertEquals( "John Doe", ( (ObjectNode) value ).findPath( "name" ).textValue() );
assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() );
assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) );
assertEquals( null, ( (ObjectNode) value ).findValue( "children" ) );
}
代码示例来源:origin: cascading/cascading-nested-json
@Test
public void testCopyExclude() throws Exception
{
Fields fields = new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "result", JSONCoercibleType.TYPE ) );
TupleEntry entry = new TupleEntry( fields, Tuple.size( 2 ) );
entry.setObject( 0, JSONData.nested );
entry.setObject( 1, JSONData.simple );
CopySpec copySpec = new CopySpec()
.exclude( "/person/ssn", "/person/children" );
JSONCopyIntoFunction function = new JSONCopyIntoFunction( new Fields( "result" ), copySpec );
TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) );
Object value = result.iterator().next().getObject( 0 );
assertNotNull( value );
assertEquals( "value", ( (ObjectNode) value ).get( "existing" ).textValue() ); // confirm we put data into an existing object
assertEquals( "John Doe", ( (ObjectNode) value ).findPath( "name" ).textValue() );
assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() );
assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) );
assertEquals( null, ( (ObjectNode) value ).findValue( "children" ) );
}
代码示例来源:origin: cascading/cascading-nested-json
@Test
public void testCopyExclude() throws Exception
{
TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) );
entry.setObject( 0, JSONData.nested );
CopySpec copySpec = new CopySpec()
.exclude( "/person/ssn", "/person/children" );
JSONCopyAsFunction function = new JSONCopyAsFunction( new Fields( "result" ), copySpec );
TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) );
Object value = result.iterator().next().getObject( 0 );
assertNotNull( value );
assertEquals( "John Doe", ( (ObjectNode) value ).findPath( "name" ).textValue() );
assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() );
assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) );
assertEquals( null, ( (ObjectNode) value ).findValue( "children" ) );
}
代码示例来源:origin: cwensel/cascading
@Test
public void testCopyIncludeDescent() throws Exception
{
Fields fields = new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "result", JSONCoercibleType.TYPE ) );
TupleEntry entry = new TupleEntry( fields, Tuple.size( 2 ) );
entry.setObject( 0, JSONData.nested );
entry.setObject( 1, JSONData.simple );
CopySpec copySpec = new CopySpec()
.include( "/person/firstName" )
.include( "/**/age" );
JSONCopyIntoFunction function = new JSONCopyIntoFunction( new Fields( "result" ), copySpec );
TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) );
Object value = result.iterator().next().getObject( 0 );
assertNotNull( value );
assertEquals( "value", ( (ObjectNode) value ).get( "existing" ).textValue() ); // confirm we put data into an existing object
assertEquals( "John", ( (ObjectNode) value ).findPath( "firstName" ).textValue() );
assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() );
assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) );
}
代码示例来源:origin: cwensel/cascading
@Test
public void testCopyIncludeWild() throws Exception
{
Fields fields = new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "result", JSONCoercibleType.TYPE ) );
TupleEntry entry = new TupleEntry( fields, Tuple.size( 2 ) );
entry.setObject( 0, JSONData.nested );
entry.setObject( 1, JSONData.simple );
CopySpec copySpec = new CopySpec()
.include( "/person/firstName" )
.include( "/*/age" );
JSONCopyIntoFunction function = new JSONCopyIntoFunction( new Fields( "result" ), copySpec );
TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) );
Object value = result.iterator().next().getObject( 0 );
assertNotNull( value );
assertEquals( "value", ( (ObjectNode) value ).get( "existing" ).textValue() ); // confirm we put data into an existing object
assertEquals( "John", ( (ObjectNode) value ).findPath( "firstName" ).textValue() );
assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() );
assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) );
}
代码示例来源:origin: cwensel/cascading
@Test
public void testCopyInclude() throws Exception
{
Fields fields = new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "result", JSONCoercibleType.TYPE ) );
TupleEntry entry = new TupleEntry( fields, Tuple.size( 2 ) );
entry.setObject( 0, JSONData.nested );
entry.setObject( 1, JSONData.simple );
CopySpec copySpec = new CopySpec()
.include( "/person/firstName" )
.include( "/person/age" );
JSONCopyIntoFunction function = new JSONCopyIntoFunction( new Fields( "result" ), copySpec );
TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) );
Object value = result.iterator().next().getObject( 0 );
assertNotNull( value );
assertEquals( "value", ( (ObjectNode) value ).get( "existing" ).textValue() ); // confirm we put data into an existing object
assertEquals( "John", ( (ObjectNode) value ).findPath( "firstName" ).textValue() );
assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() );
assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) );
}
代码示例来源:origin: cascading/cascading-nested-json
@Test
public void testCopyInclude() throws Exception
{
Fields fields = new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "result", JSONCoercibleType.TYPE ) );
TupleEntry entry = new TupleEntry( fields, Tuple.size( 2 ) );
entry.setObject( 0, JSONData.nested );
entry.setObject( 1, JSONData.simple );
CopySpec copySpec = new CopySpec()
.include( "/person/firstName" )
.include( "/person/age" );
JSONCopyIntoFunction function = new JSONCopyIntoFunction( new Fields( "result" ), copySpec );
TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) );
Object value = result.iterator().next().getObject( 0 );
assertNotNull( value );
assertEquals( "value", ( (ObjectNode) value ).get( "existing" ).textValue() ); // confirm we put data into an existing object
assertEquals( "John", ( (ObjectNode) value ).findPath( "firstName" ).textValue() );
assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() );
assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) );
}
代码示例来源:origin: cascading/cascading-nested-json
@Test
public void testCopyIncludeWild() throws Exception
{
Fields fields = new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "result", JSONCoercibleType.TYPE ) );
TupleEntry entry = new TupleEntry( fields, Tuple.size( 2 ) );
entry.setObject( 0, JSONData.nested );
entry.setObject( 1, JSONData.simple );
CopySpec copySpec = new CopySpec()
.include( "/person/firstName" )
.include( "/*/age" );
JSONCopyIntoFunction function = new JSONCopyIntoFunction( new Fields( "result" ), copySpec );
TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) );
Object value = result.iterator().next().getObject( 0 );
assertNotNull( value );
assertEquals( "value", ( (ObjectNode) value ).get( "existing" ).textValue() ); // confirm we put data into an existing object
assertEquals( "John", ( (ObjectNode) value ).findPath( "firstName" ).textValue() );
assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() );
assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) );
}
代码示例来源:origin: cascading/cascading-nested-json
@Test
public void testCopyIncludeDescent() throws Exception
{
Fields fields = new Fields( "json", JSONCoercibleType.TYPE ).append( new Fields( "result", JSONCoercibleType.TYPE ) );
TupleEntry entry = new TupleEntry( fields, Tuple.size( 2 ) );
entry.setObject( 0, JSONData.nested );
entry.setObject( 1, JSONData.simple );
CopySpec copySpec = new CopySpec()
.include( "/person/firstName" )
.include( "/**/age" );
JSONCopyIntoFunction function = new JSONCopyIntoFunction( new Fields( "result" ), copySpec );
TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) );
Object value = result.iterator().next().getObject( 0 );
assertNotNull( value );
assertEquals( "value", ( (ObjectNode) value ).get( "existing" ).textValue() ); // confirm we put data into an existing object
assertEquals( "John", ( (ObjectNode) value ).findPath( "firstName" ).textValue() );
assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() );
assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) );
}
代码示例来源:origin: cwensel/cascading
@Test
public void testCopyIncludeWild() throws Exception
{
TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) );
entry.setObject( 0, JSONData.nested );
CopySpec copySpec = new CopySpec()
.include( "/person/firstName" )
.include( "/*/age" );
JSONCopyAsFunction function = new JSONCopyAsFunction( new Fields( "result" ), copySpec );
TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) );
Object value = result.iterator().next().getObject( 0 );
assertNotNull( value );
assertEquals( "John", ( (ObjectNode) value ).findPath( "firstName" ).textValue() );
assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() );
assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) );
}
代码示例来源:origin: cascading/cascading-nested-json
@Test
public void testCopyIncludeWild() throws Exception
{
TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) );
entry.setObject( 0, JSONData.nested );
CopySpec copySpec = new CopySpec()
.include( "/person/firstName" )
.include( "/*/age" );
JSONCopyAsFunction function = new JSONCopyAsFunction( new Fields( "result" ), copySpec );
TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) );
Object value = result.iterator().next().getObject( 0 );
assertNotNull( value );
assertEquals( "John", ( (ObjectNode) value ).findPath( "firstName" ).textValue() );
assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() );
assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) );
}
代码示例来源:origin: cascading/cascading-nested-json
@Test
public void testCopyInclude() throws Exception
{
TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) );
entry.setObject( 0, JSONData.nested );
CopySpec copySpec = new CopySpec()
.include( "/person/firstName" )
.include( "/person/age" );
JSONCopyAsFunction function = new JSONCopyAsFunction( new Fields( "result" ), copySpec );
TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) );
Object value = result.iterator().next().getObject( 0 );
assertNotNull( value );
assertEquals( "John", ( (ObjectNode) value ).findPath( "firstName" ).textValue() );
assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() );
assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) );
}
代码示例来源:origin: cwensel/cascading
@Test
public void testCopyIncludeDescent() throws Exception
{
TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) );
entry.setObject( 0, JSONData.nested );
CopySpec copySpec = new CopySpec()
.include( "/person/firstName" )
.include( "/**/age" );
JSONCopyAsFunction function = new JSONCopyAsFunction( new Fields( "result" ), copySpec );
TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) );
Object value = result.iterator().next().getObject( 0 );
assertNotNull( value );
assertEquals( "John", ( (ObjectNode) value ).findPath( "firstName" ).textValue() );
assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() );
assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) );
}
代码示例来源:origin: cwensel/cascading
@Test
public void testCopyInclude() throws Exception
{
TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) );
entry.setObject( 0, JSONData.nested );
CopySpec copySpec = new CopySpec()
.include( "/person/firstName" )
.include( "/person/age" );
JSONCopyAsFunction function = new JSONCopyAsFunction( new Fields( "result" ), copySpec );
TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) );
Object value = result.iterator().next().getObject( 0 );
assertNotNull( value );
assertEquals( "John", ( (ObjectNode) value ).findPath( "firstName" ).textValue() );
assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() );
assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) );
}
代码示例来源:origin: cascading/cascading-nested-json
@Test
public void testCopyIncludeDescent() throws Exception
{
TupleEntry entry = new TupleEntry( new Fields( "json", JSONCoercibleType.TYPE ), Tuple.size( 1 ) );
entry.setObject( 0, JSONData.nested );
CopySpec copySpec = new CopySpec()
.include( "/person/firstName" )
.include( "/**/age" );
JSONCopyAsFunction function = new JSONCopyAsFunction( new Fields( "result" ), copySpec );
TupleListCollector result = invokeFunction( function, entry, new Fields( "result" ) );
Object value = result.iterator().next().getObject( 0 );
assertNotNull( value );
assertEquals( "John", ( (ObjectNode) value ).findPath( "firstName" ).textValue() );
assertEquals( 50, ( (ObjectNode) value ).findPath( "age" ).intValue() );
assertEquals( null, ( (ObjectNode) value ).findValue( "ssn" ) );
}
内容来源于网络,如有侵权,请联系作者删除!