com.google.gson.JsonElement.getAsLong()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(252)

本文整理了Java中com.google.gson.JsonElement.getAsLong()方法的一些代码示例,展示了JsonElement.getAsLong()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonElement.getAsLong()方法的具体详情如下:
包路径:com.google.gson.JsonElement
类名称:JsonElement
方法名:getAsLong

JsonElement.getAsLong介绍

[英]convenience method to get this element as a primitive long value.
[中]将此元素作为基元长值获取的简便方法。

代码示例

代码示例来源:origin: fabric8io/docker-maven-plugin

@Override
public long getCreated() {
  return json.get(CREATED).getAsLong();
}

代码示例来源:origin: MovingBlocks/Terasology

List<RecordedEvent> deserializeRecordedEvents(String path) {
  List<RecordedEvent> events = new ArrayList<>();
  createInputEventClassMap();
  JsonObject jsonObject;
  try (FileReader fileReader = new FileReader(path)) {
    JsonParser parser = new JsonParser();
    JsonElement jsonElement = parser.parse(fileReader);
    jsonObject = jsonElement.getAsJsonObject();
    JsonArray jsonEvents = jsonObject.getAsJsonArray("events");
    for (JsonElement element : jsonEvents) {
      jsonObject = element.getAsJsonObject();
      String className = jsonObject.get("event_class").getAsString();
      long refId = jsonObject.get("entityRef_ID").getAsLong();
      long index = jsonObject.get("index").getAsLong();
      long timestamp = jsonObject.get("timestamp").getAsLong();
      Event event = deserializeSpecificEventData(jsonObject.get("event_data").getAsJsonObject(), className);
      RecordedEvent re = new RecordedEvent(refId, event, timestamp, index);
      events.add(re);
    }
  } catch (Exception e) {
    logger.error("Error while deserializing event:", e);
  }
  return events;
}

代码示例来源:origin: apache/incubator-gobblin

String key = outputSchemaJsonObject.get(COLUMN_NAME_KEY).getAsString();
String type = outputSchemaJsonObject.getAsJsonObject(DATA_TYPE).get(TYPE_KEY).getAsString();
 if (!outputSchemaJsonObject.get(NULLABLE).getAsBoolean()) {
  throw new DataConversionException(
    "Field " + key + " is null or not exists but it is non-nullable by the schema.");
   break;
  case "long":
   outputRecord.addProperty(key, jsonElement.getAsLong());
   break;
  case "double":

代码示例来源:origin: apache/incubator-gobblin

JsonObject field = columnElement.getAsJsonObject();
Schema schema = new Schema();
schema.setColumnName(field.get("name").getAsString());
String dataType = field.get("type").getAsString();
String elementDataType = "string";
List<String> mapSymbols = null;
JsonObject newDataType =
  this.convertDataType(field.get("name").getAsString(), dataType, elementDataType, mapSymbols);
log.debug("ColumnName:" + field.get("name").getAsString() + ";   old datatype:" + dataType + ";   new datatype:"
  + newDataType);
schema.setLength(field.get("length").getAsLong());
schema.setPrecision(field.get("precision").getAsInt());
schema.setScale(field.get("scale").getAsInt());

代码示例来源:origin: searchbox-io/Jest

public ValueCountAggregation(String name, JsonObject valueCountAggregation) {
  super(name, valueCountAggregation);
  valueCount = valueCountAggregation.get(String.valueOf(VALUE)).getAsLong();
}

代码示例来源:origin: searchbox-io/Jest

public MissingAggregation(String name, JsonObject missingAggregation) {
  super(name, missingAggregation);
  missing = missingAggregation.get(String.valueOf(DOC_COUNT)).getAsLong();
}

代码示例来源:origin: searchbox-io/Jest

public FilterAggregation(String name, JsonObject filterAggregation) {
  super(name, filterAggregation, filterAggregation.get(String.valueOf(DOC_COUNT)).getAsLong());
}

代码示例来源:origin: searchbox-io/Jest

public long getConflictsCount() {
  return (jsonObject != null && jsonObject.has("version_conflicts")) ? jsonObject.get("version_conflicts").getAsLong() : 0L;
}

代码示例来源:origin: searchbox-io/Jest

public long getMillisTaken() {
  return (jsonObject != null && jsonObject.has("took")) ? jsonObject.get("took").getAsLong() : 0L;
}

代码示例来源:origin: searchbox-io/Jest

public long getUpdatedCount() {
  return (jsonObject != null && jsonObject.has("updated")) ? jsonObject.get("updated").getAsLong() : 0L;
}

代码示例来源:origin: apache/incubator-gobblin

private long parseRevision(JsonElement element) {
 return element.getAsJsonObject().get("revid").getAsLong();
}

代码示例来源:origin: searchbox-io/Jest

public CardinalityAggregation(String name, JsonObject cardinalityAggregation) {
  super(name, cardinalityAggregation);
  if(cardinalityAggregation.has(String.valueOf(VALUE)) && !cardinalityAggregation.get(String.valueOf(VALUE)).isJsonNull()) {
    cardinality = cardinalityAggregation.get(String.valueOf(VALUE)).getAsLong();
  }
}

代码示例来源:origin: searchbox-io/Jest

private void parseBuckets(JsonArray bucketsSource) {
  for (JsonElement bucketv : bucketsSource) {
    JsonObject bucket = bucketv.getAsJsonObject();
    Histogram histogram = new Histogram(
        bucket,
        bucket.get(String.valueOf(KEY)).getAsLong(),
        bucket.get(String.valueOf(DOC_COUNT)).getAsLong());
    histograms.add(histogram);
  }
}

代码示例来源:origin: searchbox-io/Jest

private void parseBuckets(JsonArray bucketsSource) {
  for (JsonElement bucket : bucketsSource) {
    Long time = bucket.getAsJsonObject().get(String.valueOf(KEY)).getAsLong();
    String timeAsString = bucket.getAsJsonObject().get(String.valueOf(KEY_AS_STRING)).getAsString();
    Long count = bucket.getAsJsonObject().get(String.valueOf(DOC_COUNT)).getAsLong();
    dateHistograms.add(new DateHistogram(bucket.getAsJsonObject(), time, timeAsString, count));
  }
}

代码示例来源:origin: mitreid-connect/OpenID-Connect-Java-Spring-Server

/**
 * Gets the value of the given member as a Long, null if it doesn't exist
 */
public static Long getAsLong(JsonObject o, String member) {
  if (o.has(member)) {
    JsonElement e = o.get(member);
    if (e != null && e.isJsonPrimitive()) {
      return e.getAsLong();
    } else {
      return null;
    }
  } else {
    return null;
  }
}

代码示例来源:origin: searchbox-io/Jest

public TermsAggregation(String name, JsonObject termAggregation) {
  super(name, termAggregation);
  if (termAggregation.has(String.valueOf(DOC_COUNT_ERROR_UPPER_BOUND))) {
    docCountErrorUpperBound = termAggregation.get(String.valueOf(DOC_COUNT_ERROR_UPPER_BOUND)).getAsLong();
  }
  if (termAggregation.has(String.valueOf(SUM_OTHER_DOC_COUNT))) {
    sumOtherDocCount = termAggregation.get(String.valueOf(SUM_OTHER_DOC_COUNT)).getAsLong();
  }
  if (termAggregation.has(String.valueOf(BUCKETS)) && termAggregation.get(String.valueOf(BUCKETS)).isJsonArray()) {
    parseBuckets(termAggregation.get(String.valueOf(BUCKETS)).getAsJsonArray());
  }
}

代码示例来源:origin: searchbox-io/Jest

private void parseBuckets(JsonArray bucketsSource) {
  for(JsonElement bucketElement : bucketsSource) {
    JsonObject bucket = (JsonObject) bucketElement;
    if (bucket.has(String.valueOf(KEY_AS_STRING))) {
      buckets.add(new Entry(bucket, bucket.get(String.valueOf(KEY)).getAsString(), bucket.get(String.valueOf(KEY_AS_STRING)).getAsString(), bucket.get(String.valueOf(DOC_COUNT)).getAsLong()));
    } else {
      buckets.add(new Entry(bucket, bucket.get(String.valueOf(KEY)).getAsString(), bucket.get(String.valueOf(DOC_COUNT)).getAsLong()));
    }
  }
}

代码示例来源:origin: gocd/gocd

public Optional<Long> optLong(String property) {
  if (hasJsonObject(property)) {
    try {
      return Optional.ofNullable(jsonObject.get(property).getAsLong());
    } catch (Exception e) {
      throw haltBecausePropertyIsNotAJsonString(property, jsonObject);
    }
  }
  return Optional.empty();
}

代码示例来源:origin: searchbox-io/Jest

public SignificantTermsAggregation(String name, JsonObject significantTermsAggregation) {
  super(name, significantTermsAggregation);
  if (significantTermsAggregation.has(String.valueOf(BUCKETS)) && significantTermsAggregation.get(String.valueOf(BUCKETS)).isJsonArray()) {
    parseBuckets(significantTermsAggregation.get(String.valueOf(BUCKETS)).getAsJsonArray());
  }
  if (significantTermsAggregation.has(String.valueOf(DOC_COUNT))) {
    totalCount = significantTermsAggregation.get(String.valueOf(DOC_COUNT)).getAsLong();
  }
}

代码示例来源:origin: searchbox-io/Jest

private void parseBuckets(JsonArray bucketsSource) {
  for (JsonElement bucketElement : bucketsSource) {
    JsonObject bucket = bucketElement.getAsJsonObject();
    GeoHashGrid geoHashGrid = new GeoHashGrid(
        bucket,
        bucket.get(String.valueOf(KEY)).getAsString(),
        bucket.get(String.valueOf(DOC_COUNT)).getAsLong());
    geoHashGrids.add(geoHashGrid);
  }
}

相关文章