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

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

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

JsonElement.getAsJsonNull介绍

[英]convenience method to get this element as a JsonNull. If the element is of some other type, a IllegalStateException will result. Hence it is best to use this method after ensuring that this element is of the desired type by calling #isJsonNull()first.
[中]将此元素作为JsonNull获取的方便方法。如果该元素属于其他类型,则会导致IllegalStateException。因此,最好先调用#isJsonNull()以确保此元素为所需类型,然后再使用此方法。

代码示例

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

@Override
Object convertField(JsonElement value) {
 return value.getAsJsonNull();
}

代码示例来源:origin: org.hibernate/hibernate-search-elasticsearch

@Override
protected JsonNull nullUnsafeFromElement(JsonElement element) {
  return element.getAsJsonNull();
}

代码示例来源:origin: hibernate/hibernate-search

@Override
protected JsonNull nullUnsafeFromElement(JsonElement element) {
  return element.getAsJsonNull();
}

代码示例来源:origin: org.apache.gobblin/gobblin-core

@Override
Object convertField(JsonElement value) {
 return value.getAsJsonNull();
}

代码示例来源:origin: hibernate/hibernate-search

@Override
protected JsonNull nullUnsafeFromElement(JsonElement element) {
  return element.getAsJsonNull();
}

代码示例来源:origin: org.hibernate.search/hibernate-search-backend-elasticsearch

@Override
protected JsonNull nullUnsafeFromElement(JsonElement element) {
  return element.getAsJsonNull();
}

代码示例来源:origin: vimeo/stag-java

@Override
  public JsonNull read(JsonReader in) throws IOException {
    JsonElement jsonElement = JSON_ELEMENT.read(in);
    return jsonElement != null && jsonElement.isJsonNull() ? jsonElement.getAsJsonNull() : null;
  }
}.nullSafe();

代码示例来源:origin: co.cask.wrangler/wrangler-core

/**
 * Gets a single value from the {@link JsonElement}. The value could be
 * {@link JsonObject} or {@link JsonArray} or {@link JsonPrimitive}.
 *
 * @param element value to be extracted.
 * @return the sub-element, else {@link com.google.gson.JsonNull}.
 */
public static Object getValue(JsonElement element) {
 if (element.isJsonObject()) {
  return element.getAsJsonObject();
 } else if (element.isJsonArray()) {
  return element.getAsJsonArray();
 } else if (element.isJsonPrimitive()) {
  return getValue(element.getAsJsonPrimitive());
 }
 return element.getAsJsonNull();
}

代码示例来源:origin: org.aksw.gson/gson-utils-core

public static <T> T visit(JsonElement json, JsonVisitor<T> visitor) {
  T result;
  if(json == null) {
    result = null;
  } else if(json.isJsonNull()) {
    JsonNull nil = json.getAsJsonNull();
    result = visitor.visit(nil);
  } else if(json.isJsonArray()) {
    JsonArray arr = json.getAsJsonArray();
    result = visitor.visit(arr);
  } else if(json.isJsonObject()) {
    JsonObject obj = json.getAsJsonObject();
    result = visitor.visit(obj);
  } else if(json.isJsonPrimitive()) {
    JsonPrimitive p = json.getAsJsonPrimitive();
    result = visitor.visit(p);
  } else {
    throw new RuntimeException("unknown type " + json);
  }
  return result;
}

代码示例来源:origin: org.aksw.gson/gson-utils-core

JsonNull nil = json.getAsJsonNull();
  visitor.visit(nil);
} else if(json.isJsonArray()) {

代码示例来源:origin: eatnumber1/google-gson

/**
 * Returns true if the child was visited, false if it was skipped.
 */
private boolean visitChild(JsonObject parent, String childName, JsonElement child, 
  boolean isFirst) throws IOException {
 if (child.isJsonNull()) {
  if (visitNulls) {
   visitor.visitNullObjectMember(parent, childName, isFirst);
   navigate(child.getAsJsonNull());
  } else { // Null value is being skipped.
   return false;
  }
 } else if (child.isJsonArray()) {
  JsonArray childAsArray = child.getAsJsonArray();
  visitor.visitObjectMember(parent, childName, childAsArray, isFirst);
  navigate(childAsArray);
 } else if (child.isJsonObject()) {
  JsonObject childAsObject = child.getAsJsonObject();
  visitor.visitObjectMember(parent, childName, childAsObject, isFirst);
  navigate(childAsObject);
 } else { // is a JsonPrimitive
  visitor.visitObjectMember(parent, childName, child.getAsJsonPrimitive(), isFirst);          
 }
 return true;
}

代码示例来源:origin: census-instrumentation/opencensus-java

assertThat(result.get("limit").getAsInt()).isEqualTo(0);
assertThat(result.get("offset").getAsInt()).isEqualTo(0);
assertThat(result.get("errors").getAsJsonNull()).isEqualTo(JsonNull.INSTANCE);
JsonArray data = result.get("data").getAsJsonArray();
assertThat(data).isNotNull();
assertThat(span.get("warnings").getAsJsonNull()).isEqualTo(JsonNull.INSTANCE);
assertThat(p1.get("serviceName").getAsString()).isEqualTo(SERVICE_NAME);
assertThat(p1.get("tags").getAsJsonArray().size()).isEqualTo(0);
assertThat(trace.get("warnings").getAsJsonNull()).isEqualTo(JsonNull.INSTANCE);

相关文章