当前位置: 首页>>代码示例>>Java>>正文


Java JsonPrimitive.isBoolean方法代码示例

本文整理汇总了Java中com.google.gson.JsonPrimitive.isBoolean方法的典型用法代码示例。如果您正苦于以下问题:Java JsonPrimitive.isBoolean方法的具体用法?Java JsonPrimitive.isBoolean怎么用?Java JsonPrimitive.isBoolean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.gson.JsonPrimitive的用法示例。


在下文中一共展示了JsonPrimitive.isBoolean方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convert

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
@Override
public JsonPrimitive convert(JsonPrimitive value) {
  if (value == null) {
    return new JsonPrimitive(false);
  }
  if (value.isBoolean()) {
    return value;
  }
  String str = value.getAsString();
  if (str.equalsIgnoreCase("false")) {
    return new JsonPrimitive(false);
  }
  if (str.equalsIgnoreCase("true")) {
    return new JsonPrimitive(true);
  }
  throw new ConverterException(value, this);
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:18,代码来源:BooleanConverter.java

示例2: primitive

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
/**
 * Converts a JsonPrimitive into a primitive Boolean, Double, or String.
 * 
 * @param p
 *          : JsonPrimitive
 * @return Boolean, Double, or String
 */
public static Object primitive(JsonPrimitive p) {
  Object retVal = null;
  if (p.isBoolean()) {
    retVal = p.getAsBoolean();
  } else if (p.isNumber()) {
    double doubleVal = p.getAsDouble();

    if (doubleVal == Math.rint(doubleVal)) {
      retVal = (int) doubleVal;
    } else {
      retVal = doubleVal;
    }
  } else if (p.isString()) {
    retVal = p.getAsString();
  }
  return retVal;
}
 
开发者ID:synthetichealth,项目名称:synthea_java,代码行数:25,代码来源:Utilities.java

示例3: Parameter

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
public Parameter(JsonObject param) {
    try {
        setNameAndType(param.get("name").getAsString(), param.get("type").getAsString());
        if(param.get("value").isJsonObject()){
            setJsonContent(param.getAsJsonObject("value"));
        } else {
            JsonPrimitive value = param.getAsJsonPrimitive("value");
            if(value.isString()) {
                setStringContent(value.getAsString());
            } else if(value.isNumber()) {
                setDoubleContent(value.getAsDouble());
            } else if(value.isBoolean()) {
                setBooleanContent(value.getAsBoolean());
            }
        }
    } catch (Exception e){
        throw new IllegalArgumentException("invalid parameter structure");
    }
}
 
开发者ID:DesktopRemoteManagement,项目名称:DRM-Desktop,代码行数:20,代码来源:Parameter.java

示例4: decodeFromPrimitive

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
private Variant decodeFromPrimitive ( final JsonElement json )
{
    final JsonPrimitive jsonPrim = (JsonPrimitive)json;
    if ( jsonPrim.isBoolean () )
    {
        return Variant.valueOf ( jsonPrim.getAsBoolean () );
    }
    else if ( jsonPrim.isNumber () )
    {
        return Variant.valueOf ( jsonPrim.getAsNumber () );
    }
    else
    {
        return VariantEditor.toVariant ( jsonPrim.getAsString () );
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:17,代码来源:VariantJsonDeserializer.java

示例5: keyToString

import com.google.gson.JsonPrimitive; //导入方法依赖的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();
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:20,代码来源:MapTypeAdapterFactory.java

示例6: keyToString

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
private String keyToString(JsonElement keyElement) {
  if (keyElement.isJsonPrimitive()) {
    JsonPrimitive primitive = keyElement.getAsJsonPrimitive();
    if (primitive.isNumber()) {
      return String.valueOf(primitive.getAsNumber());
    } else if (primitive.isBoolean()) {
      return Boolean.toString(primitive.getAsBoolean());
    } else if (primitive.isString()) {
      return primitive.getAsString();
    } else {
      throw new AssertionError();
    }
  } else if (keyElement.isJsonNull()) {
    return "null";
  } else {
    throw new AssertionError();
  }
}
 
开发者ID:odoo-mobile-intern,项目名称:odoo-work,代码行数:19,代码来源:MapTypeAdapterFactory.java

示例7: assertEqualsJsonPrimitive

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
private void assertEqualsJsonPrimitive(JsonPrimitive expectedPrimitive, JsonPrimitive actualPrimitive, String path) {
	if (expectedPrimitive.isString()) {
		Assert.assertEquals("strings at " + path + " do not match",
			expectedPrimitive.getAsString(), actualPrimitive.getAsString());
	}
	if (expectedPrimitive.isBoolean()) {
		Assert.assertEquals("booleans at " + path + " do not match",
			expectedPrimitive.getAsBoolean(), actualPrimitive.getAsBoolean());
	}
	if (expectedPrimitive.isNumber()) {
		boolean equal = expectedPrimitive.getAsBigDecimal().compareTo(actualPrimitive.getAsBigDecimal()) == 0;
		Assert.assertTrue("numbers at " + path + " do not match expected <" +
				expectedPrimitive.getAsBigDecimal() + "> but was:<" +
				actualPrimitive.getAsBigDecimal() + ">",
			equal);
	}
	Assert.assertEquals("expected primitive (" + expectedPrimitive + ") and actual primitive (" +
		actualPrimitive + ") at " + path + " are not equal; ", expectedPrimitive, actualPrimitive);
}
 
开发者ID:LogicalOverflow,项目名称:java-champion-gg-wrapper,代码行数:20,代码来源:ChampionGGTest.java

示例8: deserialize

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
@Override
public Holder deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
  JsonObject root = (JsonObject) json;

  ImmutableHolder.Builder builder = ImmutableHolder.builder();

  if (root.has("id")) {
    builder.id(root.get("id").getAsString());
  }

  JsonElement value = root.get(VALUE_PROPERTY);
  if (value == null) {
    throw new JsonParseException(String.format("%s not found for %s in JSON", VALUE_PROPERTY, type));
  }

  if (value.isJsonObject()) {
    final String valueTypeName = value.getAsJsonObject().get(Holder.TYPE_PROPERTY).getAsString();
    try {
      Class<?> valueType = Class.forName(valueTypeName);
      builder.value(context.deserialize(value, valueType));
    } catch (ClassNotFoundException e) {
      throw new JsonParseException(String.format("Couldn't construct value class %s for %s", valueTypeName, type), e);
    }
  } else if (value.isJsonPrimitive()) {
    final JsonPrimitive primitive = value.getAsJsonPrimitive();
    if (primitive.isString()) {
      builder.value(primitive.getAsString());
    } else if (primitive.isNumber()) {
      builder.value(primitive.getAsInt());
    } else if (primitive.isBoolean()) {
      builder.value(primitive.getAsBoolean());
    }
  } else {
    throw new JsonParseException(
        String.format("Couldn't deserialize %s : %s. Not a primitive or object", VALUE_PROPERTY, value));
  }

  return builder.build();

}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:41,代码来源:HolderJsonSerializer.java

示例9: unwarpPrimitive

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
@Override
public Object unwarpPrimitive(JsonPrimitive primitive) {
    if (primitive.isBoolean()) {
        return primitive.getAsBoolean();
    } else if (primitive.isNumber()) {
        return primitive.getAsNumber();
    } else if (primitive.isString()) {
        return primitive.getAsString();
    } else {
        throw new IllegalArgumentException("Unknown primitive type: " + primitive);
    }
}
 
开发者ID:lucko,项目名称:helper,代码行数:13,代码来源:AbstractGsonConverter.java

示例10: write

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
public void write(JsonWriter out, JsonElement value) throws IOException {
    if (value == null || value.isJsonNull()) {
        out.nullValue();
    } else if (value.isJsonPrimitive()) {
        JsonPrimitive primitive = value.getAsJsonPrimitive();
        if (primitive.isNumber()) {
            out.value(primitive.getAsNumber());
        } else if (primitive.isBoolean()) {
            out.value(primitive.getAsBoolean());
        } else {
            out.value(primitive.getAsString());
        }
    } else if (value.isJsonArray()) {
        out.beginArray();
        i$ = value.getAsJsonArray().iterator();
        while (i$.hasNext()) {
            write(out, (JsonElement) i$.next());
        }
        out.endArray();
    } else if (value.isJsonObject()) {
        out.beginObject();
        for (Entry<String, JsonElement> e : value.getAsJsonObject().entrySet()) {
            out.name((String) e.getKey());
            write(out, (JsonElement) e.getValue());
        }
        out.endObject();
    } else {
        throw new IllegalArgumentException("Couldn't write " + value.getClass());
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:31,代码来源:TypeAdapters.java

示例11: getValueType

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
private static String getValueType(Object value1) {
    if (value1 instanceof JsonPrimitive) {
        JsonPrimitive jp = (JsonPrimitive) value1;
        if (jp.isNumber() && jp.toString().contains(".")) {
            return "Double";
        }
        return jp.isBoolean() ? "Boolean" : jp.isNumber() ? "Integer" : jp.isString() ? "String" : "String";
    } else if (value1 instanceof JsonObject || value1 instanceof JsonArray || value1 instanceof LinkedHashMap) {
        return "Object[data]";
    }
    return "String";
}
 
开发者ID:ajtdnyy,项目名称:PackagePlugin,代码行数:13,代码来源:MainFrame.java

示例12: replaceWithTestData

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
private static String replaceWithTestData(final JsonElement sourceTestData, String inputString) {
if(sourceTestData != null) {
        if(inputString != null) {
            if(inputString.startsWith("$(") && inputString.endsWith(")")) {
                inputString = inputString.substring("$(".length(), inputString.length() - ")".length());

                String[] pathElements = inputString.split("\\.");
                if(pathElements != null && pathElements.length > 0) {
                    JsonElement elemPointer = sourceTestData;
                    for(String element : pathElements) {
                        if(elemPointer.isJsonObject() && elemPointer.getAsJsonObject().has(element)) {
                            elemPointer = elemPointer.getAsJsonObject().get(element);
                            continue;
                        }
                        else {
                            elemPointer = null;
                            break;
                        }
                    }
                    if(elemPointer != null && elemPointer.isJsonPrimitive()) {
                        JsonPrimitive primitive = elemPointer.getAsJsonPrimitive();
                        if(primitive.isString() || primitive.isNumber())
                            return primitive.getAsString();
                        else if(primitive.isBoolean())
                            return primitive.getAsBoolean()?"true":"false";
                    }
                }
            }
        }
    }
    return inputString;
}
 
开发者ID:andrewjc,项目名称:kheera-testrunner-android,代码行数:33,代码来源:TableConverter.java

示例13: translateScenarioArguments

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
private void translateScenarioArguments(List<Object> parameters) {
    // TODO: Lookup and replace the list of parameters
    // with data from the test data file

    if(testData != null) {
        for(int i=0;i<parameters.size();i++) {
            if(parameters.get(i) instanceof String) {
                String raw = (String)parameters.get(i);
                if(raw.startsWith("$(") && raw.endsWith(")")) {
                    raw = raw.substring("$(".length(), raw.length() - ")".length());

                    String[] pathElements = raw.split("\\.");
                    if(pathElements != null && pathElements.length > 0) {
                        JsonElement elemPointer = testData;
                        for(String element : pathElements) {
                            if(elemPointer.isJsonObject() && elemPointer.getAsJsonObject().has(element)) {
                                elemPointer = elemPointer.getAsJsonObject().get(element);
                                continue;
                            }
                            else {
                                elemPointer = null;
                                break;
                            }
                        }
                        if(elemPointer != null && elemPointer.isJsonPrimitive()) {
                            JsonPrimitive primitive = elemPointer.getAsJsonPrimitive();
                            if(primitive.isString() || primitive.isNumber())
                                parameters.set(i, primitive.getAsString());
                            else if(primitive.isBoolean())
                                parameters.set(i, primitive.getAsBoolean());
                        }
                    }
                }
            }
        }
    }
}
 
开发者ID:andrewjc,项目名称:kheera-testrunner-android,代码行数:38,代码来源:FeatureFileExecutor.java

示例14: toString

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
/**
 * Gets a human-readable description of the given JsonElement's type.  For example: "a number (4)"
 */
public static String toString(JsonElement json)
{
    String s = org.apache.commons.lang3.StringUtils.abbreviateMiddle(String.valueOf((Object)json), "...", 10);

    if (json == null)
    {
        return "null (missing)";
    }
    else if (json.isJsonNull())
    {
        return "null (json)";
    }
    else if (json.isJsonArray())
    {
        return "an array (" + s + ")";
    }
    else if (json.isJsonObject())
    {
        return "an object (" + s + ")";
    }
    else
    {
        if (json.isJsonPrimitive())
        {
            JsonPrimitive jsonprimitive = json.getAsJsonPrimitive();

            if (jsonprimitive.isNumber())
            {
                return "a number (" + s + ")";
            }

            if (jsonprimitive.isBoolean())
            {
                return "a boolean (" + s + ")";
            }
        }

        return s;
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:44,代码来源:JsonUtils.java

示例15: toString

import com.google.gson.JsonPrimitive; //导入方法依赖的package包/类
/**
 * Gets a human-readable description of the given JsonElement's type.  For example: "a number (4)"
 */
public static String toString(JsonElement p_151222_0_)
{
    String s = org.apache.commons.lang3.StringUtils.abbreviateMiddle(String.valueOf((Object)p_151222_0_), "...", 10);

    if (p_151222_0_ == null)
    {
        return "null (missing)";
    }
    else if (p_151222_0_.isJsonNull())
    {
        return "null (json)";
    }
    else if (p_151222_0_.isJsonArray())
    {
        return "an array (" + s + ")";
    }
    else if (p_151222_0_.isJsonObject())
    {
        return "an object (" + s + ")";
    }
    else
    {
        if (p_151222_0_.isJsonPrimitive())
        {
            JsonPrimitive jsonprimitive = p_151222_0_.getAsJsonPrimitive();

            if (jsonprimitive.isNumber())
            {
                return "a number (" + s + ")";
            }

            if (jsonprimitive.isBoolean())
            {
                return "a boolean (" + s + ")";
            }
        }

        return s;
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:44,代码来源:JsonUtils.java


注:本文中的com.google.gson.JsonPrimitive.isBoolean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。