本文整理了Java中com.fasterxml.jackson.databind.JsonNode.path()
方法的一些代码示例,展示了JsonNode.path()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.path()
方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.JsonNode
类名称:JsonNode
方法名:path
[英]This method is similar to #get(int), except that instead of returning null if no such element exists (due to index being out of range, or this node not being an array), a "missing node" (node that returns true for #isMissingNode) will be returned. This allows for convenient and safe chained access via path calls.
[中]此方法与#get(int)类似,只是如果不存在此类元素(由于索引超出范围,或者此节点不是数组),则不会返回null,而是返回“缺少的节点”(为#isMissingNode返回true的节点)。这允许通过路径调用进行方便和安全的链接访问。
代码示例来源:origin: liferay/liferay-portal
/**
* Parses the responseJsonNode JsonNode of the form
*
* @return description of the Form or empty string if not present in the
* String
*/
@Override
public String getDescription() {
JsonNode jsonNode = responseJsonNode.path(
HydraConstants.FieldNames.DESCRIPTION);
return jsonNode.asText();
}
代码示例来源:origin: joelittlejohn/jsonschema2pojo
private boolean isObject(JsonNode node) {
return node.path("type").asText().equals("object");
}
代码示例来源:origin: joelittlejohn/jsonschema2pojo
private boolean isArray(JsonNode node) {
return node.path("type").asText().equals("array");
}
代码示例来源:origin: knowm/XChange
private CoinbaseAddress getAddressFromNode(JsonNode addressNode)
throws com.fasterxml.jackson.databind.exc.InvalidFormatException {
final JsonNode nestedAddressNode = addressNode.path("address");
final String address = nestedAddressNode.path("address").asText();
final String callbackUrl = nestedAddressNode.path("callback_url").asText();
final String label = nestedAddressNode.path("label").asText();
final Date createdAt =
DateUtils.fromISO8601DateString(nestedAddressNode.path("created_at").asText());
return new CoinbaseAddress(address, callbackUrl, label, createdAt);
}
}
代码示例来源:origin: Activiti/Activiti
protected boolean isEqualToCurrentLocalizationValue(String language,
String id,
String propertyName,
String propertyValue,
ObjectNode infoNode) {
boolean isEqual = false;
JsonNode localizationNode = infoNode.path("localization").path(language).path(id).path(propertyName);
if (!localizationNode.isMissingNode() && !localizationNode.isNull() && localizationNode.asText().equals(propertyValue)) {
isEqual = true;
}
return isEqual;
}
代码示例来源:origin: knowm/XChange
public static CoinbaseMoney getCoinbaseMoneyFromNode(JsonNode node) {
final String amount = node.path("amount").asText();
final String currency = node.path("currency").asText();
return new CoinbaseMoney(currency, new BigDecimal(amount));
}
代码示例来源:origin: knowm/XChange
@Override
public BitmexFee deserialize(JsonParser jsonParser, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
ObjectCodec oc = jsonParser.getCodec();
JsonNode node = oc.readTree(jsonParser);
BigDecimal volume = new BigDecimal(node.path(0).asText());
BigDecimal fee = new BigDecimal(node.path(1).asText());
return new BitmexFee(volume, fee);
}
}
代码示例来源:origin: knowm/XChange
@Override
public KrakenFee deserialize(JsonParser jsonParser, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
ObjectCodec oc = jsonParser.getCodec();
JsonNode node = oc.readTree(jsonParser);
BigDecimal volume = new BigDecimal(node.path(0).asText());
BigDecimal fee = new BigDecimal(node.path(1).asText());
return new KrakenFee(volume, fee);
}
}
代码示例来源:origin: knowm/XChange
@Override
public GateioPublicOrder deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
final ObjectCodec oc = jp.getCodec();
final JsonNode tickerNode = oc.readTree(jp);
final BigDecimal price = new BigDecimal(tickerNode.path(0).asText());
final BigDecimal amount = new BigDecimal(tickerNode.path(1).asText());
return new GateioPublicOrder(price, amount);
}
}
代码示例来源:origin: Graylog2/graylog2-server
public Set<String> getClosedIndices(final Collection<String> indices) {
final JsonNode catIndices = catIndices(indices, "index", "status");
final ImmutableSet.Builder<String> closedIndices = ImmutableSet.builder();
for (JsonNode jsonElement : catIndices) {
if (jsonElement.isObject()) {
final String index = jsonElement.path("index").asText(null);
final String status = jsonElement.path("status").asText(null);
if (index != null && "close".equals(status)) {
closedIndices.add(index);
}
}
}
return closedIndices.build();
}
代码示例来源:origin: Graylog2/graylog2-server
private static QueryParsingException buildQueryParsingException(Supplier<String> errorMessage,
JsonNode rootCause,
List<String> reasons) {
final JsonNode lineJson = rootCause.path("line");
final Integer line = lineJson.isInt() ? lineJson.asInt() : null;
final JsonNode columnJson = rootCause.path("col");
final Integer column = columnJson.isInt() ? columnJson.asInt() : null;
final String index = rootCause.path("index").asText(null);
return new QueryParsingException(errorMessage.get(), line, column, index, reasons);
}
代码示例来源:origin: knowm/XChange
@Override
public KrakenPublicOrder deserialize(JsonParser jsonParser, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
ObjectCodec oc = jsonParser.getCodec();
JsonNode node = oc.readTree(jsonParser);
if (node.isArray()) {
BigDecimal price = new BigDecimal(node.path(0).asText());
BigDecimal volume = new BigDecimal(node.path(1).asText());
long timestamp = node.path(2).asLong();
return new KrakenPublicOrder(price, volume, timestamp);
}
return null;
}
}
代码示例来源:origin: knowm/XChange
@Override
public CoinbaseCurrency deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
ObjectCodec oc = jp.getCodec();
JsonNode node = oc.readTree(jp);
if (node.isArray()) {
String name = node.path(0).asText();
String isoCode = node.path(1).asText();
return new CoinbaseCurrency(name, isoCode);
}
return null;
}
}
代码示例来源:origin: knowm/XChange
@Override
public BitZPublicOrder deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
ObjectCodec oc = p.getCodec();
JsonNode node = oc.readTree(p);
if (node.isArray()) {
BigDecimal price = new BigDecimal(node.path(0).asText());
BigDecimal volume = new BigDecimal(node.path(1).asText());
return new BitZPublicOrder(price, volume);
}
return null;
}
}
代码示例来源:origin: Graylog2/graylog2-server
public Set<NodeFileDescriptorStats> getFileDescriptorStats() {
final JsonNode nodes = catNodes("name", "host", "ip", "fileDescriptorMax");
final ImmutableSet.Builder<NodeFileDescriptorStats> setBuilder = ImmutableSet.builder();
for (JsonNode jsonElement : nodes) {
if (jsonElement.isObject()) {
final String name = jsonElement.path("name").asText();
final String host = jsonElement.path("host").asText(null);
final String ip = jsonElement.path("ip").asText();
final JsonNode fileDescriptorMax = jsonElement.path("fileDescriptorMax");
final Long maxFileDescriptors = fileDescriptorMax.isLong() ? fileDescriptorMax.asLong() : null;
setBuilder.add(NodeFileDescriptorStats.create(name, ip, host, maxFileDescriptors));
}
}
return setBuilder.build();
}
代码示例来源:origin: Graylog2/graylog2-server
public Optional<String> nodeIdToName(String nodeId) {
return Optional.ofNullable(getNodeInfo(nodeId).path("name").asText(null));
}
代码示例来源:origin: Graylog2/graylog2-server
private String getScrollIdFromResult(JestResult result) {
return result.getJsonObject().path("_scroll_id").asText();
}
代码示例来源:origin: Graylog2/graylog2-server
public Optional<String> nodeIdToHostName(String nodeId) {
return Optional.ofNullable(getNodeInfo(nodeId).path("host").asText(null));
}
代码示例来源:origin: knowm/XChange
public static CoinbaseMoney getCoinbaseMoneyFromCents(JsonNode node) {
final String amount = node.path("cents").asText();
final String currency = node.path("currency_iso").asText();
final int numDecimals = (currency.equalsIgnoreCase("BTC")) ? 8 : 2;
return new CoinbaseMoney(currency, new BigDecimal(amount).movePointLeft(numDecimals));
}
代码示例来源:origin: Graylog2/graylog2-server
private static double timestampValue(final JsonNode json) {
final JsonNode value = json.path(Message.FIELD_TIMESTAMP);
if (value.isNumber()) {
return value.asDouble(-1.0);
} else if (value.isTextual()) {
try {
return Double.parseDouble(value.asText());
} catch (NumberFormatException e) {
log.debug("Unable to parse timestamp", e);
return -1.0;
}
} else {
return -1.0;
}
}
内容来源于网络,如有侵权,请联系作者删除!