本文整理汇总了Java中com.google.gson.JsonElement.getAsBoolean方法的典型用法代码示例。如果您正苦于以下问题:Java JsonElement.getAsBoolean方法的具体用法?Java JsonElement.getAsBoolean怎么用?Java JsonElement.getAsBoolean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.JsonElement
的用法示例。
在下文中一共展示了JsonElement.getAsBoolean方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import com.google.gson.JsonElement; //导入方法依赖的package包/类
public Object deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
if (json.isJsonObject()) {
JsonObject obj = json.getAsJsonObject();
try {
typeOfT = Class.forName(obj.get("class").getAsString());
} catch (ClassNotFoundException e) {
throw new JsonParseException(e);
}
JsonElement prim = obj.get("primitive");
if (null != prim && prim.getAsBoolean()) {
json = obj.get("value");
}
} /*
* else TODO errore durante il cast da Object[] to T[] if
* (json.isJsonArray()) { JsonParser parser = new JsonParser();
* JsonArray array =json.getAsJsonArray(); Object[] arr = new
* Object[array.size()]; for(int i = 0; i < array.size(); i++) {
* arr[i] = context.deserialize(array.get(i),
* array.get(i).getClass()); } return arr; }
*/
return gson.fromJson(json, typeOfT);
}
示例2: getBoolean
import com.google.gson.JsonElement; //导入方法依赖的package包/类
/**
* Gets the boolean value of the given JsonElement. Expects the second parameter to be the name of the element's
* field if an error message needs to be thrown.
*/
public static boolean getBoolean(JsonElement p_151216_0_, String p_151216_1_)
{
if (p_151216_0_.isJsonPrimitive())
{
return p_151216_0_.getAsBoolean();
}
else
{
throw new JsonSyntaxException("Expected " + p_151216_1_ + " to be a Boolean, was " + toString(p_151216_0_));
}
}
示例3: getBoolean
import com.google.gson.JsonElement; //导入方法依赖的package包/类
/**
* Gets the boolean value of the given JsonElement. Expects the second parameter to be the name of the element's
* field if an error message needs to be thrown.
*/
public static boolean getBoolean(JsonElement json, String memberName)
{
if (json.isJsonPrimitive())
{
return json.getAsBoolean();
}
else
{
throw new JsonSyntaxException("Expected " + memberName + " to be a Boolean, was " + toString(json));
}
}
示例4: deserialize
import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public ArtRef.Autogen deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
if (json.getAsBoolean()) {
return ArtRef.Autogen.TRUE;
}
return ArtRef.Autogen.FALSE;
}
示例5: deserialize
import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
try {
return json.getAsInt();
} catch (NumberFormatException e) {
return (json.getAsBoolean()) ? 1 : 0;
}
}
示例6: completeResponse
import com.google.gson.JsonElement; //导入方法依赖的package包/类
/**
* Complete a response.
*
* @param surveyId the survey id of the survey you want to complete the response
* @param responseId the response id of the response you want to complete
* @param date the date where the response will be completed (submitdate)
* @return true if the response was successfuly completed
* @throws LimesurveyRCException the limesurvey rc exception
*/
public boolean completeResponse(int surveyId, int responseId, LocalDateTime date) throws LimesurveyRCException {
Map<String, String> responseData = new HashMap<>();
responseData.put("submitdate", date.format(DateTimeFormatter.ISO_LOCAL_DATE) + " " + date.format(DateTimeFormatter.ISO_LOCAL_TIME));
JsonElement result = updateResponse(surveyId, responseId, responseData);
if (!result.getAsBoolean()) {
throw new LimesurveyRCException(result.getAsString());
}
return true;
}
示例7: 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();
}
}
示例8: getValue
import com.google.gson.JsonElement; //导入方法依赖的package包/类
private static <T> T getValue(JsonElement element, T compared) throws IllegalStateException, ClassCastException, IllegalArgumentException {
if (compared instanceof Double) {
return (T)(new Double(element.getAsDouble()));
}
else if (compared instanceof Integer) {
return (T)(new Integer(element.getAsInt()));
}
else if (compared instanceof JsonObject) {
return (T)element.getAsJsonObject();
}
else if (compared instanceof JsonArray) {
return (T)element.getAsJsonArray();
}
else if (compared instanceof String) {
return (T)element.getAsString();
}
else if (compared instanceof Boolean) {
return (T)(new Boolean(element.getAsBoolean()));
}
throw new IllegalArgumentException();
}
示例9: fromJson
import com.google.gson.JsonElement; //导入方法依赖的package包/类
@Override
public Boolean fromJson(final JsonElement json)
{
return json.getAsBoolean();
}
示例10: BooleanValue
import com.google.gson.JsonElement; //导入方法依赖的package包/类
protected BooleanValue(final JsonElement v, final boolean deprecated, final String encryptionProfile)
{
super(deprecated, encryptionProfile);
this.value = v.getAsBoolean();
}
示例11: getAsBoolean
import com.google.gson.JsonElement; //导入方法依赖的package包/类
public static Boolean getAsBoolean(JsonElement element) {
return isNull(element) ? null : element.getAsBoolean();
}
示例12: getBoolean
import com.google.gson.JsonElement; //导入方法依赖的package包/类
public static boolean getBoolean(JsonObject p_getBoolean_0_, String p_getBoolean_1_, boolean p_getBoolean_2_)
{
JsonElement jsonelement = p_getBoolean_0_.get(p_getBoolean_1_);
return jsonelement == null ? p_getBoolean_2_ : jsonelement.getAsBoolean();
}
示例13: isEnabled
import com.google.gson.JsonElement; //导入方法依赖的package包/类
private static boolean isEnabled(JsonElement node) {
JsonElement disabled = node.getAsJsonObject().get("disabled");
return (disabled == null || !disabled.getAsBoolean());
}
示例14: getBooleanOrDefaultValue
import com.google.gson.JsonElement; //导入方法依赖的package包/类
static Boolean getBooleanOrDefaultValue(JsonElement jsonElement, Boolean defaultValue)
{
return jsonElement != null ? jsonElement.getAsBoolean() : defaultValue;
}
示例15: ifNullFalse
import com.google.gson.JsonElement; //导入方法依赖的package包/类
static Boolean ifNullFalse(JsonElement jsonElement)
{
return jsonElement != null && !jsonElement.isJsonNull() ? jsonElement.getAsBoolean() : false;
}