本文整理了Java中com.fasterxml.jackson.databind.JsonNode.asLong()
方法的一些代码示例,展示了JsonNode.asLong()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.asLong()
方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.JsonNode
类名称:JsonNode
方法名:asLong
[英]Method that will try to convert value of this node to a Java long. Numbers are coerced using default Java rules; booleans convert to 0 (false) and 1 (true), and Strings are parsed using default Java language integer parsing rules.
If representation cannot be converted to an long (including structured types like Objects and Arrays), default value of 0 will be returned; no exceptions are thrown.
[中]方法,该方法将尝试将此节点的值转换为Java long。使用默认Java规则强制数字;布尔值转换为0(false)和1(true),字符串使用默认的Java语言整数解析规则进行解析。
如果无法将表示转换为long(包括对象和数组等结构化类型),则返回默认值0;没有抛出异常。
代码示例来源:origin: SeldonIO/seldon-server
public Impression(JsonNode j)
{
consumer = j.get("consumer").asText();
rectag = j.get("rectag").asText();
variation = j.get("abkey").asText();
time = j.get("time").asLong();
String impType = j.get("click").asText();
if (impType.equals("IMP"))
imp = 1;
else if (impType.equals("CTR"))
click = 1;
}
代码示例来源: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: SeldonIO/seldon-server
public Request(JsonNode j)
{
consumer = j.get("consumer").asText();
time = j.get("time").asLong();
httpmethod = j.get("httpmethod").asText();
path = createPath(j.get("path").asText());
exectime = j.get("exectime").asInt();
count = 1;
}
代码示例来源: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: apache/incubator-pinot
private static Object extractSingleValue(JsonNode jsonValue, FieldSpec.DataType dataType) {
Preconditions.checkArgument(jsonValue.isValueNode());
switch (dataType) {
case INT:
return jsonValue.asInt();
case LONG:
return jsonValue.asLong();
case FLOAT:
return (float) jsonValue.asDouble();
case DOUBLE:
return jsonValue.asDouble();
case STRING:
return jsonValue.asText();
default:
throw new IllegalArgumentException();
}
}
}
代码示例来源:origin: Activiti/Activiti
protected void setOutcomeConditionExpression(SequenceFlow flow, JsonNode expressionNode) {
Long formId = null;
if (expressionNode.get("outcomeFormId") != null && !(expressionNode.get("outcomeFormId").isNull())) {
formId = expressionNode.get("outcomeFormId").asLong();
}
String operator = null;
if (expressionNode.get("operator") != null && expressionNode.get("operator").isNull() == false) {
operator = expressionNode.get("operator").asText();
}
String outcomeName = null;
if (expressionNode.get("outcomeName") != null && !(expressionNode.get("outcomeName").isNull())) {
outcomeName = expressionNode.get("outcomeName").asText();
}
if (formId != null && operator != null && outcomeName != null) {
flow.setConditionExpression("${form" + formId + "outcome " + operator + " " + outcomeName + "}");
addExtensionElement("conditionFormId", String.valueOf(formId), flow);
addExtensionElement("conditionOperator", operator, flow);
addExtensionElement("conditionOutcomeName", outcomeName, flow);
}
}
代码示例来源:origin: knowm/XChange
@Override
public KrakenSpreads deserialize(JsonParser jsonParser, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
List<KrakenSpread> krakenTrades = new ArrayList<>();
long last = 0;
ObjectCodec oc = jsonParser.getCodec();
JsonNode node = oc.readTree(jsonParser);
Iterator<Entry<String, JsonNode>> tradesResultIterator = node.fields();
while (tradesResultIterator.hasNext()) {
Entry<String, JsonNode> entry = tradesResultIterator.next();
String key = entry.getKey();
JsonNode value = entry.getValue();
if (key == "last") {
last = value.asLong();
} else if (value.isArray()) {
for (JsonNode jsonSpreadNode : value) {
long time = jsonSpreadNode.path(0).asLong();
BigDecimal bid = new BigDecimal(jsonSpreadNode.path(1).asText());
BigDecimal ask = new BigDecimal(jsonSpreadNode.path(2).asText());
krakenTrades.add(new KrakenSpread(time, bid, ask));
}
}
}
return new KrakenSpreads(krakenTrades, last);
}
}
代码示例来源:origin: Graylog2/graylog2-server
@Nullable
private Object valueNode(JsonNode jsonNode) {
if (jsonNode.isInt()) {
return jsonNode.asInt();
} else if (jsonNode.isLong()) {
return jsonNode.asLong();
} else if (jsonNode.isIntegralNumber()) {
return jsonNode.asLong();
} else if (jsonNode.isFloatingPointNumber()) {
return jsonNode.asDouble();
} else if (jsonNode.isBoolean()) {
return jsonNode.asBoolean();
} else if (jsonNode.isNull()) {
return null;
} else {
return jsonNode.asText();
}
}
代码示例来源:origin: apache/usergrid
@Override
Map<String, Object> userFromResource(String externalToken) {
MultivaluedMap<String, String> formData = getMultivaluedMapImpl();
formData.add("grant_type", "urn:pingidentity.com:oauth2:grant_type:validate_bearer");
formData.add("client_id", clientId);
formData.add("client_secret", clientSecret);
formData.add("token", externalToken);
JsonNode node = client.target(apiUrl).request()
.post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED_TYPE), JsonNode.class);
String rawEmail = node.get("access_token").get("subject").asText();
Map<String, Object> userMap = new HashMap<String, Object>();
userMap.put("expiration", node.get("expires_in").asLong());
userMap.put("username", pingUsernameFrom(rawEmail));
userMap.put("name", "pinguser");
userMap.put("email", rawEmail);
return userMap;
}
代码示例来源:origin: knowm/XChange
last = value.asLong();
} else if (value.isArray()) {
for (JsonNode jsonSpreadNode : value) {
long time = jsonSpreadNode.path(0).asLong();
BigDecimal open = new BigDecimal(jsonSpreadNode.path(1).asText());
BigDecimal high = new BigDecimal(jsonSpreadNode.path(2).asText());
BigDecimal low = new BigDecimal(jsonSpreadNode.path(3).asText());
BigDecimal close = new BigDecimal(jsonSpreadNode.path(4).asText());
BigDecimal vwap = new BigDecimal(jsonSpreadNode.path(5).asText());
BigDecimal volume = new BigDecimal(jsonSpreadNode.path(6).asText());
long count = jsonSpreadNode.path(7).asLong();
krakenOHLCs.add(new KrakenOHLC(time, open, high, low, close, vwap, volume, count));
代码示例来源:origin: zendesk/maxwell
@Override
public ColumnDef deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
JsonNode node = jp.getCodec().readTree(jp);
String type = node.get("type").asText();
String name = node.get("name").asText();
String charset = node.path("charset").asText();
boolean signed = node.path("signed").asBoolean(false);
String[] enumValues = null;
JsonNode enumValueNode = node.get("enum-values");
if ( enumValueNode != null ) {
ArrayList<String> values = new ArrayList<>();
for ( JsonNode n : enumValueNode )
values.add(n.asText());
enumValues = (String[]) values.toArray(new String[0]);
}
Long columnLength = null;
JsonNode columnLengthNode = node.get("column-length");
if ( columnLengthNode != null ) {
columnLength = columnLengthNode.asLong();
}
return ColumnDef.build(name, charset, type, (short) 0, signed, enumValues, columnLength);
}
}
代码示例来源:origin: knowm/XChange
timestamp = node.asLong();
} else if (key.equalsIgnoreCase("username")) {
username = node.asText();
} else if (key.equalsIgnoreCase("error")) {
error = node.asText();
} else if (node.isObject()) {
BigDecimal available =
node.has("available") ? new BigDecimal(node.get("available").asText()) : null;
BigDecimal orders =
node.has("orders") ? new BigDecimal(node.get("orders").asText()) : null;
代码示例来源:origin: apache/incubator-druid
return val.asLong();
return charsetFix(val.asText());
代码示例来源:origin: knowm/XChange
@Override
public KucoinActiveOrder deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
JsonNode root = p.readValueAsTree();
if (root.isArray()) {
Date timestamp = new Date(root.get(0).asLong());
KucoinOrderType orderType = KucoinOrderType.valueOf(root.get(1).asText());
BigDecimal price = root.get(2).decimalValue();
BigDecimal amount = root.get(3).decimalValue();
BigDecimal dealAmount = root.get(4).decimalValue(); // amount already filled
String orderOid = root.get(5).textValue();
return new KucoinActiveOrder(timestamp, orderType, price, amount, dealAmount, orderOid);
} else {
throw new RuntimeException("KucoinDealOrder should have an array as root node!");
}
}
}
代码示例来源:origin: knowm/XChange
@Override
public KrakenPublicTrades deserialize(JsonParser jsonParser, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
List<KrakenPublicTrade> krakenTrades = new ArrayList<>();
long last = 0;
ObjectCodec oc = jsonParser.getCodec();
JsonNode node = oc.readTree(jsonParser);
Iterator<Entry<String, JsonNode>> tradesResultIterator = node.fields();
while (tradesResultIterator.hasNext()) {
Entry<String, JsonNode> entry = tradesResultIterator.next();
String key = entry.getKey();
JsonNode value = entry.getValue();
if (key == "last") {
last = value.asLong();
} else if (value.isArray()) {
for (JsonNode tradeJsonNode : value) {
BigDecimal price = new BigDecimal(tradeJsonNode.path(0).asText());
BigDecimal volume = new BigDecimal(tradeJsonNode.path(1).asText());
double time = tradeJsonNode.path(2).asDouble();
KrakenType type = KrakenType.fromString(tradeJsonNode.path(3).asText());
KrakenOrderType orderType = KrakenOrderType.fromString(tradeJsonNode.path(4).asText());
String miscellaneous = tradeJsonNode.path(5).asText();
krakenTrades.add(
new KrakenPublicTrade(price, volume, time, type, orderType, miscellaneous));
}
}
}
return new KrakenPublicTrades(krakenTrades, last);
}
}
代码示例来源:origin: knowm/XChange
String id = node.get("id").asText();
String name = node.get("name").asText();
String symbol = node.get("symbol").asText();
String websiteSlug = node.get("website_slug").asText();
Date lastUpdated = new Date(node.get("last_updated").asLong() * 1000);
BigDecimal rank = new BigDecimal(node.get("rank").asInt());
BigDecimal circulatingSupply = new BigDecimal(node.get("circulating_supply").asDouble());
代码示例来源:origin: knowm/XChange
final String errorText = errorNode.asText();
if (errorText.equals("Invalid symbols pair")) {
return new CexIOOpenOrders();
if (openOrdersNode.isArray()) {
for (JsonNode openOrderNode : openOrdersNode) {
final long id = openOrderNode.path("id").asLong();
final long time = openOrderNode.path("time").asLong();
final Type type = Type.valueOf(openOrderNode.path("type").asText());
final BigDecimal price = new BigDecimal(openOrderNode.path("price").asText());
final BigDecimal amount = new BigDecimal(openOrderNode.path("amount").asText());
final BigDecimal pending = new BigDecimal(openOrderNode.path("pending").asText());
代码示例来源:origin: SeldonIO/seldon-server
public void parse(JsonNode j)
consumer = j.get("consumer").asText();
time = j.get("time").asLong();
count = 1;
if (j.has("prediction"))
variation = meta.get("variation").asText();
else
variation = "default";
if (meta.has("modelName"))
model = meta.get("modelName").asText();
else
model = "default";
代码示例来源:origin: knowm/XChange
@Override
public KucoinDealOrder deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
JsonNode root = p.readValueAsTree();
if (root.isArray()) {
Long timestamp = root.get(0).asLong();
KucoinOrderType orderType = KucoinOrderType.valueOf(root.get(1).asText());
BigDecimal price = root.get(2).decimalValue();
BigDecimal amount = root.get(3).decimalValue();
BigDecimal volume = root.get(4).decimalValue();
return new KucoinDealOrder(timestamp, orderType, price, amount, volume);
} else {
throw new RuntimeException("KucoinDealOrder should have an array as root node!");
}
}
}
代码示例来源:origin: apache/nifi
@Override
public RedisStateMap deserialize(final byte[] data) throws IOException {
if (data == null || data.length == 0) {
return null;
}
final RedisStateMap.Builder builder = new RedisStateMap.Builder();
try (final JsonParser jsonParser = jsonFactory.createParser(data)) {
final JsonNode rootNode = jsonParser.readValueAsTree();
builder.version(rootNode.get(FIELD_VERSION).asLong());
builder.encodingVersion(rootNode.get(FIELD_ENCODING).asInt());
final JsonNode stateValuesNode = rootNode.get(FIELD_STATE_VALUES);
stateValuesNode.fields().forEachRemaining(e -> builder.stateValue(e.getKey(), e.getValue().asText()));
}
return builder.build();
}
内容来源于网络,如有侵权,请联系作者删除!