本文整理了Java中com.google.gson.JsonElement.isJsonNull()
方法的一些代码示例,展示了JsonElement.isJsonNull()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonElement.isJsonNull()
方法的具体详情如下:
包路径:com.google.gson.JsonElement
类名称:JsonElement
方法名:isJsonNull
[英]provides check for verifying if this element represents a null value or not.
[中]提供检查以验证此元素是否表示空值。
代码示例来源:origin: fabric8io/docker-maven-plugin
@Override
public String getIPAddress() {
if (json.has(NETWORK_SETTINGS) && !json.get(NETWORK_SETTINGS).isJsonNull()) {
JsonObject networkSettings = json.getAsJsonObject(NETWORK_SETTINGS);
if (!networkSettings.get(IP).isJsonNull()) {
return networkSettings.get(IP).getAsString();
}
}
return null;
}
代码示例来源:origin: searchbox-io/Jest
protected List<String> extractSort(JsonArray sort) {
if (sort == null) {
return null;
}
List<String> retval = new ArrayList<String>(sort.size());
for (JsonElement sortValue : sort) {
retval.add(sortValue.isJsonNull() ? "" : sortValue.getAsString());
}
return retval;
}
代码示例来源: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: pinterest/secor
public void convert(JsonElement value, ColumnVector vect, int row) {
if (value == null || value.isJsonNull()) {
vect.noNulls = false;
vect.isNull[row] = true;
} else {
StructColumnVector vector = (StructColumnVector) vect;
JsonObject obj = value.getAsJsonObject();
for (int c = 0; c < childrenConverters.length; ++c) {
JsonElement elem = obj.get(fieldNames.get(c));
childrenConverters[c].convert(elem, vector.fields[c], row);
}
}
}
}
代码示例来源:origin: fabric8io/docker-maven-plugin
private void logWarnings(JsonObject body) {
if (body.has("Warnings")) {
JsonElement warningsObj = body.get("Warnings");
if (!warningsObj.isJsonNull()) {
JsonArray warnings = (JsonArray) warningsObj;
for (int i = 0; i < warnings.size(); i++) {
log.warn(warnings.get(i).getAsString());
}
}
}
}
代码示例来源:origin: chanjarster/weixin-java-tools
public WxMpMaterialNews deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
WxMpMaterialNews wxMpMaterialNews = new WxMpMaterialNews();
JsonObject json = jsonElement.getAsJsonObject();
if (json.get("news_item") != null && !json.get("news_item").isJsonNull()) {
JsonArray articles = json.getAsJsonArray("news_item");
for (JsonElement article1 : articles) {
JsonObject articleInfo = article1.getAsJsonObject();
WxMpMaterialNews.WxMpMaterialNewsArticle article = WxMpGsonBuilder.create().fromJson(articleInfo, WxMpMaterialNews.WxMpMaterialNewsArticle.class);
wxMpMaterialNews.addArticle(article);
}
}
return wxMpMaterialNews;
}
}
代码示例来源:origin: square/wire
private Object parseValue(FieldBinding<?, ?> fieldBinding, JsonElement element) {
if (fieldBinding.label.isRepeated()) {
if (element.isJsonNull()) {
return Collections.emptyList();
if (element.isJsonNull()) {
return Collections.emptyMap();
Class<?> valueType = fieldBinding.singleAdapter().javaType;
JsonObject object = element.getAsJsonObject();
Map<Object, Object> result = new LinkedHashMap<>(object.size());
for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
代码示例来源:origin: fabric8io/docker-maven-plugin
@Override
public Map<String, String> getCustomNetworkIpAddresses() {
if (json.has(NETWORK_SETTINGS) && !json.get(NETWORK_SETTINGS).isJsonNull()) {
JsonObject networkSettings = json.getAsJsonObject(NETWORK_SETTINGS);
if (networkSettings.has(NETWORKS) && !networkSettings.get(NETWORKS).isJsonNull()) {
return extractNetworks(networkSettings);
}
}
return null;
}
代码示例来源:origin: Mojang/DataFixerUpper
@Override
public JsonElement mergeInto(final JsonElement input, final JsonElement key, final JsonElement value) {
final JsonObject output;
if (input.isJsonNull()) {
output = new JsonObject();
} else if (input.isJsonObject()) {
output = new JsonObject();
input.getAsJsonObject().entrySet().forEach(entry -> output.add(entry.getKey(), entry.getValue()));
} else {
return input;
}
output.add(key.getAsString(), value);
return output;
}
代码示例来源:origin: fabric8io/docker-maven-plugin
@Override
public Map<String, PortBinding> getPortBindings() {
if (json.get(PORTS).isJsonNull()) {
return Collections.emptyMap();
}
return mapPortBindings(json.getAsJsonArray(PORTS));
}
代码示例来源:origin: searchbox-io/Jest
public BulkResultItem(String operation, JsonObject values) {
this.operation = operation;
this.index = values.get("_index").getAsString();
this.type = values.get("_type").getAsString();
this.id = values.has("_id") && !values.get("_id").isJsonNull() ? values.get("_id").getAsString() : null;
this.status = values.get("status").getAsInt();
this.error = values.has("error") ? values.get("error").toString() : null;
if (values.has("error") && values.get("error").isJsonObject()) {
final JsonObject errorObject = values.get("error").getAsJsonObject();
this.errorType = errorObject.has("type") ? errorObject.get("type").getAsString() : null;
this.errorReason = errorObject.has("reason") ? errorObject.get("reason").getAsString() : null;
} else {
this.errorType = null;
this.errorReason = null;
}
this.version = values.has("_version") ? values.get("_version").getAsInt() : null;
}
代码示例来源:origin: chanjarster/weixin-java-tools
public WxMpMaterialUploadResult deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
WxMpMaterialUploadResult uploadResult = new WxMpMaterialUploadResult();
JsonObject uploadResultJsonObject = json.getAsJsonObject();
if (uploadResultJsonObject.get("url") != null && !uploadResultJsonObject.get("url").isJsonNull()) {
uploadResult.setUrl(GsonHelper.getAsString(uploadResultJsonObject.get("url")));
}
if (uploadResultJsonObject.get("media_id") != null && !uploadResultJsonObject.get("media_id").isJsonNull()) {
uploadResult.setMediaId(GsonHelper.getAsString(uploadResultJsonObject.get("media_id")));
}
return uploadResult;
}
代码示例来源:origin: sixt/ja-micro
public String extractString(JsonObject json, String name) {
if (json != null) {
int dotIndex = name.indexOf('.');
if (dotIndex > 0) {
String baseName = name.substring(0, dotIndex);
JsonElement childElement = json.get(baseName);
return extractString((JsonObject) childElement, name.substring(dotIndex + 1));
}
JsonElement element = json.get(name);
if (element != null && ! element.isJsonNull()) {
return element.getAsString();
}
}
return null;
}
代码示例来源:origin: chanjarster/weixin-java-tools
public WxMpMassNews deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
WxMpMassNews wxMpMassNews = new WxMpMassNews();
JsonObject json = jsonElement.getAsJsonObject();
if (json.get("media_id") != null && !json.get("media_id").isJsonNull()) {
JsonArray articles = json.getAsJsonArray("articles");
for (JsonElement article1 : articles) {
JsonObject articleInfo = article1.getAsJsonObject();
WxMpMassNews.WxMpMassNewsArticle article = WxMpGsonBuilder.create().fromJson(articleInfo, WxMpMassNews.WxMpMassNewsArticle.class);
wxMpMassNews.addArticle(article);
}
}
return wxMpMassNews;
}
}
代码示例来源:origin: pinterest/secor
public void convert(JsonElement value, ColumnVector vect, int row) {
if (value == null || value.isJsonNull()) {
vect.noNulls = false;
vect.isNull[row] = true;
} else {
BytesColumnVector vector = (BytesColumnVector) vect;
byte[] bytes = value.getAsString().getBytes(
StandardCharsets.UTF_8);
vector.setRef(row, bytes, 0, bytes.length);
}
}
}
代码示例来源:origin: apache/incubator-gobblin
@Override
public R read(JsonReader in) throws IOException {
JsonElement element = Streams.parse(in);
if (element.isJsonNull()) {
return readNull();
}
JsonObject jsonObject = element.getAsJsonObject();
if (this.typeToken.getRawType() == Optional.class) {
if (jsonObject.has(OBJECT_TYPE)) {
return (R) Optional.of(readValue(jsonObject, null));
} else if (jsonObject.entrySet().isEmpty()) {
return (R) Optional.absent();
} else {
throw new IOException("No class found for Optional value.");
}
}
return this.readValue(jsonObject, this.typeToken);
}
代码示例来源:origin: searchbox-io/Jest
public StatsAggregation(String name, JsonObject statsAggregation) {
super(name, statsAggregation);
this.count = statsAggregation.get(String.valueOf(COUNT)).getAsLong();
this.min = !statsAggregation.has(String.valueOf(MIN)) || statsAggregation.get(String.valueOf(MIN)).isJsonNull() ?
null : statsAggregation.get(String.valueOf(MIN)).getAsDouble();
this.max = !statsAggregation.has(String.valueOf(MAX)) || statsAggregation.get(String.valueOf(MAX)).isJsonNull() ?
null : statsAggregation.get(String.valueOf(MAX)).getAsDouble();
this.avg = !statsAggregation.has(String.valueOf(AVG)) || statsAggregation.get(String.valueOf(AVG)).isJsonNull() ?
null : statsAggregation.get(String.valueOf(AVG)).getAsDouble();
this.sum = !statsAggregation.has(String.valueOf(SUM)) || statsAggregation.get(String.valueOf(SUM)).isJsonNull() ?
null : statsAggregation.get(String.valueOf(SUM)).getAsDouble();
}
代码示例来源:origin: fabric8io/docker-maven-plugin
@Override
public Map<String, PortBinding> getPortBindings() {
if (json.has(NETWORK_SETTINGS) && !json.get(NETWORK_SETTINGS).isJsonNull()) {
JsonObject networkSettings = json.getAsJsonObject(NETWORK_SETTINGS);
if (networkSettings.has(PORTS) && !networkSettings.get(PORTS).isJsonNull()) {
return createPortBindings(networkSettings.getAsJsonObject(PORTS));
}
}
return new HashMap<>();
}
代码示例来源:origin: fabric8io/docker-maven-plugin
private Map<String, String> extractNetworks(JsonObject networkSettings) {
JsonObject networks = networkSettings.getAsJsonObject(NETWORKS);
Set<String> keys = networks.keySet();
if (keys == null || keys.isEmpty()) {
return null;
}
Map<String, String> results = new HashMap<>();
for (String key : keys) {
JsonObject net = networks.getAsJsonObject(key);
if (net.has(IP) && !net.get(IP).isJsonNull()) {
results.put(key, net.get(IP).getAsString());
}
}
return results;
}
代码示例来源:origin: chanjarster/weixin-java-tools
public WxAccessToken deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
WxAccessToken accessToken = new WxAccessToken();
JsonObject accessTokenJsonObject = json.getAsJsonObject();
if (accessTokenJsonObject.get("access_token") != null && !accessTokenJsonObject.get("access_token").isJsonNull()) {
accessToken.setAccessToken(GsonHelper.getAsString(accessTokenJsonObject.get("access_token")));
}
if (accessTokenJsonObject.get("expires_in") != null && !accessTokenJsonObject.get("expires_in").isJsonNull()) {
accessToken.setExpiresIn(GsonHelper.getAsPrimitiveInt(accessTokenJsonObject.get("expires_in")));
}
return accessToken;
}
内容来源于网络,如有侵权,请联系作者删除!