本文整理汇总了Java中com.google.gson.JsonElement.isJsonNull方法的典型用法代码示例。如果您正苦于以下问题:Java JsonElement.isJsonNull方法的具体用法?Java JsonElement.isJsonNull怎么用?Java JsonElement.isJsonNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.JsonElement
的用法示例。
在下文中一共展示了JsonElement.isJsonNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClientJsonSetting
import com.google.gson.JsonElement; //导入方法依赖的package包/类
private static JsonObject getClientJsonSetting(String client, Context context) {
Log.i("LiQueryBuilder", "Reading client settings from configurations");
String settingJsonStr = LiSDKManager.getInstance().getFromSecuredPreferences(context, LI_DEFAULT_SDK_SETTINGS);
JsonObject clientSettings = getDefault(client);
JsonObject serverSettingJson = null;
if (settingJsonStr != null && !settingJsonStr.isEmpty()) {
JsonElement jsonElement = new JsonParser().parse(settingJsonStr);
if (!jsonElement.isJsonNull() && jsonElement.isJsonObject()) {
serverSettingJson = jsonElement.getAsJsonObject();
}
}
overrideDefaultSettings(clientSettings, serverSettingJson);
return clientSettings;
}
示例2: makeConfigParam
import com.google.gson.JsonElement; //导入方法依赖的package包/类
private ConfigurationParam makeConfigParam(String key, JsonElement value) {
if (value.isJsonNull()) {
throw new NullPointerException("value for key '" + key + "' is null!");
}
ConfigurationParam param = new ConfigurationParam();
param.setKey(key);
String valueStr;
if (value.isJsonPrimitive() && value.getAsJsonPrimitive().isString()) {
// toString would return the string with quotes around it which we don't want
valueStr = value.getAsString();
} else {
valueStr = value.toString();
}
param.setValue(valueStr);
return param;
}
示例3: put
import com.google.gson.JsonElement; //导入方法依赖的package包/类
private void put(JsonElement value) {
if (this.pendingName != null) {
if (!value.isJsonNull() || getSerializeNulls()) {
((JsonObject) peek()).add(this.pendingName, value);
}
this.pendingName = null;
} else if (this.stack.isEmpty()) {
this.product = value;
} else {
JsonElement element = peek();
if (element instanceof JsonArray) {
((JsonArray) element).add(value);
return;
}
throw new IllegalStateException();
}
}
示例4: keyToString
import com.google.gson.JsonElement; //导入方法依赖的package包/类
private String keyToString(JsonElement keyElement) {
if (keyElement.isJsonPrimitive()) {
JsonPrimitive primitive = keyElement.getAsJsonPrimitive();
if (primitive.isNumber()) {
return String.valueOf(primitive.getAsNumber());
}
if (primitive.isBoolean()) {
return Boolean.toString(primitive.getAsBoolean());
}
if (primitive.isString()) {
return primitive.getAsString();
}
throw new AssertionError();
} else if (keyElement.isJsonNull()) {
return "null";
} else {
throw new AssertionError();
}
}
示例5: unwrapElement
import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
@Nullable
public Object unwrapElement(JsonElement element) {
if (element.isJsonNull()) {
return null;
} else if (element.isJsonArray()) {
return unwrapArray(element.getAsJsonArray());
} else if (element.isJsonObject()) {
return unwrapObject(element.getAsJsonObject());
} else if (element.isJsonPrimitive()) {
return unwarpPrimitive(element.getAsJsonPrimitive());
} else {
throw new IllegalArgumentException("Unknown element type: " + element);
}
}
示例6: getDataPoint
import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public DataPoint getDataPoint(long timestamp, JsonElement json)
{
long value = 0L;
if (!json.isJsonNull())
value = json.getAsLong();
return new LongDataPoint(timestamp, value);
}
示例7: encodeCanonicalElement
import com.google.gson.JsonElement; //导入方法依赖的package包/类
private static void encodeCanonicalElement(JsonElement el, JsonWriterUnchecked writer) {
try {
if (el.isJsonObject()) encodeCanonical(el.getAsJsonObject(), writer);
else if (el.isJsonPrimitive()) writer.jsonValue(el.toString());
else if (el.isJsonArray()) encodeCanonicalArray(el.getAsJsonArray(), writer);
else if (el.isJsonNull()) writer.nullValue();
else throw new JsonCanonicalException("Unexpected JSON type, this is a bug, report!");
} catch (IOException e) {
throw new JsonCanonicalException(e);
}
}
示例8: getDouble
import com.google.gson.JsonElement; //导入方法依赖的package包/类
/**
*
* @param path
* @return
*/
public Double getDouble(String path, Double defaultVal) {
JsonElement jsonElt = getLastJsonEltInPath(path);
if (jsonElt == null || jsonElt.isJsonNull()) {
return defaultVal;
} else {
return jsonElt.getAsDouble();
}
}
示例9: isResponseSuccess
import com.google.gson.JsonElement; //导入方法依赖的package包/类
public boolean isResponseSuccess(JsonElement jsonElement) {
if (!jsonElement.isJsonNull()) {
if (jsonElement.isJsonObject()) {
JsonObject json = jsonElement.getAsJsonObject();
//{"errors": ["Username is missing", "Password cannot be blank"]}
return !json.has("errors");
} else {
return true;
}
} else {
return false;
}
}
示例10: getSvgPath
import com.google.gson.JsonElement; //导入方法依赖的package包/类
private static void getSvgPath(JsonElement path, StringBuilder d) {
if (path != null && !path.isJsonNull()) {
if (path.isJsonArray()) {
Iterator<JsonElement> linesIt = path.getAsJsonArray().iterator();
while (linesIt.hasNext()) {
if (d.length() > 0) {
d.append(" ");
}
getSvgPath(linesIt.next(), d);
}
} else {
d.append(path.getAsString());
}
}
}
示例11: getBoolean
import com.google.gson.JsonElement; //导入方法依赖的package包/类
/**
*
* @param path
* @return
*/
public Boolean getBoolean(String path, Boolean defaultVal) {
JsonElement jsonElt = getLastJsonEltInPath(path);
if (jsonElt == null || jsonElt.isJsonNull()) {
return defaultVal;
} else {
return jsonElt.getAsBoolean();
}
}
示例12: getBigInteger
import com.google.gson.JsonElement; //导入方法依赖的package包/类
/**
*
* @param path
* @return
*/
public BigInteger getBigInteger(String path, BigInteger defaultVal) {
JsonElement jsonElt = getLastJsonEltInPath(path);
if (jsonElt == null || jsonElt.isJsonNull()) {
return defaultVal;
} else {
return jsonElt.getAsBigInteger();
}
}
示例13: deserialize
import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public TimeZone deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
return json.isJsonNull() ? null : TimeZone.getTimeZone(json.getAsJsonPrimitive().getAsString());
}
示例14: getJsonArrayOrNull
import com.google.gson.JsonElement; //导入方法依赖的package包/类
static JsonArray getJsonArrayOrNull(JsonElement jsonElement)
{
return jsonElement != null && !jsonElement.isJsonNull() ? jsonElement.getAsJsonArray() : null;
}
示例15: getStringOrNull
import com.google.gson.JsonElement; //导入方法依赖的package包/类
public static String getStringOrNull(JsonElement jsonElement)
{
return jsonElement.isJsonNull() ? null : jsonElement.getAsString();
}