本文整理汇总了Java中com.fasterxml.jackson.databind.JsonNode.findValue方法的典型用法代码示例。如果您正苦于以下问题:Java JsonNode.findValue方法的具体用法?Java JsonNode.findValue怎么用?Java JsonNode.findValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.JsonNode
的用法示例。
在下文中一共展示了JsonNode.findValue方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEventFromJson
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Parse an object node in order to create an {@link Event} object
*
* @param objectNode object node to convert to {@link Event}
* @return {@link Event} converted format
* @see TwitterMock#SOURCE
*/
@Override
public Event getEventFromJson(ObjectNode objectNode) {
Date startDate = Date.from(Instant.ofEpochMilli(objectNode.findValue("timestamp_ms").asLong()));
Date endDate = Date.from(Instant.now());
JsonNode jsonNode = objectNode.findValue("place");
JsonNode jsonCoordinates = jsonNode.findValue("coordinates");
String description = objectNode.findValue("text").toString();
LatLong latLong = jsonToLatLong(jsonCoordinates);
try {
return new Event(latLong, startDate, endDate, description, SOURCE);
} catch (IllegalArgumentException | NullPointerException err) {
LOGGER.error(err.getMessage());
return null;
}
}
示例2: extractAttributesFromResourceAsJson
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private String extractAttributesFromResourceAsJson(Resource resource) throws IOException {
JsonApiResponse response = new JsonApiResponse();
response.setEntity(resource);
// deserialize using the objectMapper so it becomes json-api
String newRequestBody = objectMapper.writeValueAsString(resource);
JsonNode node = objectMapper.readTree(newRequestBody);
JsonNode attributes = node.findValue("attributes");
return objectMapper.writeValueAsString(attributes);
}
示例3: jsonToLatLong
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
* Parse a json node object in order to create a valid {@link LatLong} object
*
* @param objectNode {@link LatLong} in JSON format
* @return a valid {@link LatLong}
* @see LatLong
* @see DBpediaMock#VALUE
*/
private static LatLong jsonToLatLong(JsonNode objectNode) {
JsonNode latitudeNode = objectNode.findValue("latitude");
JsonNode longitudeNode = objectNode.findValue("longitude");
if (latitudeNode != null && longitudeNode != null) {
double latitude = latitudeNode.findValue(VALUE).asDouble();
double longitude = longitudeNode.findValue(VALUE).asDouble();
return new LatLong(latitude, longitude);
}
return null;
}
示例4: doGetEC2InstanceRegion
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
static String doGetEC2InstanceRegion(final String json) {
if (null != json) {
try {
JsonNode node = MAPPER.readTree(json.getBytes(StringUtils.UTF8));
JsonNode region = node.findValue(REGION);
return region.asText();
} catch (Exception e) {
log.warn("Unable to parse EC2 instance info (" + json
+ ") : " + e.getMessage(), e);
}
}
return null;
}
示例5: doGetEC2InstanceRegion
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
static String doGetEC2InstanceRegion(final String json) {
if (null != json) {
try {
JsonNode node = mapper.readTree(json.getBytes(StringUtils.UTF8));
JsonNode region = node.findValue(REGION);
return region.asText();
} catch (Exception e) {
log.warn("Unable to parse EC2 instance info (" + json
+ ") : " + e.getMessage(), e);
}
}
return null;
}
示例6: parse
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private static C4CTicket parse(String content) throws JsonProcessingException, IOException, C4CTicketNotFoundException {
ObjectMapper mapper = new ObjectMapper();
JsonNode jNode = mapper.readTree(content);
JsonNode resultsArray = jNode.findValue(RESULTS_JSON_TREE_NODE);
if(resultsArray.isNull() || !resultsArray.elements().hasNext()){
throw new C4CTicketNotFoundException();
}
C4CTicket c4cTicket = createC4CTicketObject(jNode);
return c4cTicket;
}
示例7: apply
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public JDefinedClass apply(String nodeName, JsonNode node, JDefinedClass jclass, Schema schema) {
List<String> requiredFieldMethods = new ArrayList<String>();
JsonNode properties = schema.getContent().get("properties");
for (Iterator<JsonNode> iterator = node.elements(); iterator.hasNext(); ) {
String requiredArrayItem = iterator.next().asText();
if (requiredArrayItem.isEmpty()) {
continue;
}
JsonNode propertyNode = null;
if (properties != null) {
propertyNode = properties.findValue(requiredArrayItem);
}
String fieldName = ruleFactory.getNameHelper().getPropertyName(requiredArrayItem, propertyNode);
JFieldVar field = jclass.fields().get(fieldName);
if (field == null) {
continue;
}
addJavaDoc(field);
if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations()) {
addNotNullAnnotation(field);
}
if (ruleFactory.getGenerationConfig().isIncludeJsr305Annotations()) {
addNonnullAnnotation(field);
}
requiredFieldMethods.add(getGetterName(fieldName, field.type(), node));
requiredFieldMethods.add(getSetterName(fieldName, node));
}
updateGetterSetterJavaDoc(jclass, requiredFieldMethods);
return jclass;
}
示例8: isNotNull
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private boolean isNotNull(JsonNode jsonNode, String field){
return jsonNode.findValue(field) != null && !jsonNode.get(field).isNull();
}