本文整理了Java中com.google.gson.JsonElement.getAsBoolean()
方法的一些代码示例,展示了JsonElement.getAsBoolean()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonElement.getAsBoolean()
方法的具体详情如下:
包路径:com.google.gson.JsonElement
类名称:JsonElement
方法名:getAsBoolean
[英]convenience method to get this element as a boolean value.
[中]将此元素作为布尔值获取的方便方法。
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
public static Boolean getAsBoolean(JsonObject parent, String name) {
JsonElement el = parent.get(name);
return el == null ? null : el.getAsBoolean();
}
代码示例来源:origin: fabric8io/docker-maven-plugin
@Override
public boolean isRunning() {
JsonObject state = json.getAsJsonObject(STATE);
return state.get(RUNNING).getAsBoolean();
}
代码示例来源:origin: MovingBlocks/Terasology
if (obj.has("params") && obj.get("params").isJsonObject()) {
JsonObject params = obj.get("params").getAsJsonObject();
for (Map.Entry<String, JsonElement> prop : params.entrySet()) {
if (prop.getValue().isJsonPrimitive()) {
metadata.floatParams.put(prop.getKey(), prop.getValue().getAsFloat());
} else if (prop.getValue().getAsJsonPrimitive().isBoolean()) {
metadata.intParams.put(prop.getKey(), (prop.getValue().getAsBoolean()) ? 1 : 0);
代码示例来源:origin: apache/incubator-gobblin
JsonObject field = columnElement.getAsJsonObject();
Schema schema = new Schema();
schema.setColumnName(field.get("name").getAsString());
String dataType = field.get("type").getAsString();
String elementDataType = "string";
List<String> mapSymbols = null;
JsonObject newDataType =
this.convertDataType(field.get("name").getAsString(), dataType, elementDataType, mapSymbols);
log.debug("ColumnName:" + field.get("name").getAsString() + "; old datatype:" + dataType + "; new datatype:"
+ newDataType);
schema.setPrecision(field.get("precision").getAsInt());
schema.setScale(field.get("scale").getAsInt());
schema.setNullable(field.get("nillable").getAsBoolean());
schema.setFormat(null);
schema.setComment((field.get("label").isJsonNull() ? null : field.get("label").getAsString()));
schema
.setDefaultValue((field.get("defaultValue").isJsonNull() ? null : field.get("defaultValue").getAsString()));
schema.setUnique(field.get("unique").getAsBoolean());
代码示例来源:origin: MovingBlocks/Terasology
@Override
public BlockShapeData deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
BlockShapeData shape = new BlockShapeData();
JsonObject shapeObj = json.getAsJsonObject();
if (shapeObj.has(DISPLAY_NAME)) {
shape.setDisplayName(shapeObj.getAsJsonPrimitive(DISPLAY_NAME).getAsString());
}
for (BlockPart part : BlockPart.values()) {
if (shapeObj.has(part.toString().toLowerCase(Locale.ENGLISH))) {
JsonObject meshObj = shapeObj.getAsJsonObject(part.toString().toLowerCase(Locale.ENGLISH));
shape.setMeshPart(part, (BlockMeshPart) context.deserialize(meshObj, BlockMeshPart.class));
if (part.isSide() && meshObj.has(FULL_SIDE)) {
shape.setBlockingSide(part.getSide(), meshObj.get(FULL_SIDE).getAsBoolean());
}
}
}
if (shapeObj.has(COLLISION) && shapeObj.get(COLLISION).isJsonObject()) {
JsonObject collisionInfo = shapeObj.get(COLLISION).getAsJsonObject();
processCollision(context, shape, collisionInfo);
} else {
shape.setCollisionShape(COLLISION_SHAPE_FACTORY.getNewUnitCube());
shape.setCollisionSymmetric(true);
}
return shape;
}
代码示例来源:origin: apache/incubator-gobblin
if (jsonObject.get("done").getAsBoolean()) {
setPullStatus(false);
} else {
setNextUrl(this.sfConnector.getFullUri(
jsonObject.get("nextRecordsUrl").getAsString().replaceAll(this.sfConnector.getServicesDataEnvPath(), "")));
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
public static Boolean getAsBoolean(JsonObject parent, String name, boolean defaultValue) {
JsonElement el = parent.get(name);
return el == null ? defaultValue : el.getAsBoolean();
}
代码示例来源:origin: apache/incubator-gobblin
String key = outputSchemaJsonObject.get(COLUMN_NAME_KEY).getAsString();
String type = outputSchemaJsonObject.getAsJsonObject(DATA_TYPE).get(TYPE_KEY).getAsString();
if (!outputSchemaJsonObject.get(NULLABLE).getAsBoolean()) {
throw new DataConversionException(
"Field " + key + " is null or not exists but it is non-nullable by the schema.");
break;
case "boolean":
outputRecord.addProperty(key, jsonElement.getAsBoolean());
break;
case "string":
代码示例来源:origin: fabric8io/docker-maven-plugin
public boolean isRunning() {
return json.get(RUNNING).getAsBoolean();
}
代码示例来源:origin: SpigotMC/BungeeCord
component.setColor( ChatColor.valueOf( object.get( "color" ).getAsString().toUpperCase( Locale.ROOT ) ) );
component.setBold( object.get( "bold" ).getAsBoolean() );
component.setItalic( object.get( "italic" ).getAsBoolean() );
component.setUnderlined( object.get( "underlined" ).getAsBoolean() );
component.setStrikethrough( object.get( "strikethrough" ).getAsBoolean() );
component.setObfuscated( object.get( "obfuscated" ).getAsBoolean() );
代码示例来源:origin: searchbox-io/Jest
public boolean didTimeOut() {
return (jsonObject != null && jsonObject.has("timed_out")) ? jsonObject.get("timed_out").getAsBoolean() : false;
}
代码示例来源:origin: mitreid-connect/OpenID-Connect-Java-Spring-Server
/**
* Gets the value of the given member as a boolean, null if it doesn't exist
*/
public static Boolean getAsBoolean(JsonObject o, String member) {
if (o.has(member)) {
JsonElement e = o.get(member);
if (e != null && e.isJsonPrimitive()) {
return e.getAsBoolean();
} else {
return null;
}
} else {
return null;
}
}
代码示例来源:origin: gocd/gocd
public static EnvironmentVariableConfig fromJSON(JsonObject jsonReader) {
String name = jsonReader.get("name").getAsString();
String value = jsonReader.get("value").getAsString();
boolean secure = jsonReader.has("secure") && jsonReader.get("secure").getAsBoolean();
EnvironmentVariableConfig environmentConfig = new EnvironmentVariableConfig(new GoCipher(), name, value, secure);
return environmentConfig;
}
代码示例来源:origin: SonarSource/sonarqube
private void formatIgnoredConditions(JsonObject json) {
JsonElement ignoredConditions = json.get("ignoredConditions");
if (ignoredConditions != null) {
projectStatusBuilder.setIgnoredConditions(ignoredConditions.getAsBoolean());
} else {
projectStatusBuilder.setIgnoredConditions(false);
}
}
代码示例来源:origin: gocd/gocd
@Override
public AgentRuntimeInfo deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObject = json.getAsJsonObject();
AgentIdentifier identifier = context.deserialize(jsonObject.get("identifier"), AgentIdentifier.class);
AgentRuntimeStatus runtimeStatus = context.deserialize(jsonObject.get("runtimeStatus"), AgentRuntimeStatus.class);
AgentBuildingInfo buildingInfo = context.deserialize(jsonObject.get("buildingInfo"), AgentBuildingInfo.class);
String location = jsonObject.has("location") ? jsonObject.get("location").getAsString() : null;
Long usableSpace = jsonObject.has("usableSpace") ? jsonObject.get("usableSpace").getAsLong() : null;
String operatingSystemName = jsonObject.has("operatingSystemName") ? jsonObject.get("operatingSystemName").getAsString() : null;
String cookie = jsonObject.has("cookie") ? jsonObject.get("cookie").getAsString() : null;
boolean supportsBuildCommandProtocol = jsonObject.has("supportsBuildCommandProtocol") && jsonObject.get("supportsBuildCommandProtocol").getAsBoolean();
String elasticPluginId = jsonObject.has("elasticPluginId") ? jsonObject.get("elasticPluginId").getAsString() : null;
String elasticAgentId = jsonObject.has("elasticAgentId") ? jsonObject.get("elasticAgentId").getAsString() : null;
AgentRuntimeInfo info;
if (elasticPluginId == null || StringUtils.isBlank(elasticPluginId)) {
info = new AgentRuntimeInfo(identifier, runtimeStatus, location, cookie, supportsBuildCommandProtocol);
} else {
info = new ElasticAgentRuntimeInfo(identifier, runtimeStatus, location, cookie, elasticAgentId, elasticPluginId);
}
info.setUsableSpace(usableSpace);
info.setOperatingSystem(operatingSystemName);
info.setSupportsBuildCommandProtocol(supportsBuildCommandProtocol);
info.setBuildingInfo(buildingInfo);
return info;
}
}
代码示例来源:origin: MovingBlocks/Terasology
private void inputEventSetup(InputEvent event, JsonObject jsonObject) {
float delta = jsonObject.get("delta").getAsFloat();
boolean consumed = jsonObject.get("consumed").getAsBoolean();
EntityRef target = new RecordedEntityRef(jsonObject.get("target").getAsLong(), (LowLevelEntityManager) this.entityManager);
JsonObject aux = jsonObject.get("hitNormal").getAsJsonObject();
Vector3f hitNormal = new Vector3f(aux.get("x").getAsFloat(), aux.get("y").getAsFloat(), aux.get("z").getAsFloat());
aux = jsonObject.get("hitPosition").getAsJsonObject();
Vector3f hitPosition = new Vector3f(aux.get("x").getAsFloat(), aux.get("y").getAsFloat(), aux.get("z").getAsFloat());
aux = jsonObject.get("targetBlockPosition").getAsJsonObject();
Vector3i targetBlockPosition = new Vector3i(aux.get("x").getAsInt(), aux.get("y").getAsInt(), aux.get("z").getAsInt());
event.setTargetInfo(target, targetBlockPosition, hitPosition, hitNormal);
}
}
代码示例来源:origin: apache/incubator-gobblin
if (!jsonBody.get("hasErrors").getAsBoolean()) {
return;
JsonArray results = jsonBody.get("results").getAsJsonArray();
for (JsonElement jsonElem : results) {
JsonObject json = jsonElem.getAsJsonObject();
int subStatusCode = json.get("statusCode").getAsInt();
if (subStatusCode < 400) {
continue;
代码示例来源:origin: MovingBlocks/Terasology
private void processCollision(JsonDeserializationContext context, BlockShapeData shape, JsonObject collisionInfo) {
if (collisionInfo.has(PITCH_SYMMETRIC) && collisionInfo.get(PITCH_SYMMETRIC).isJsonPrimitive()
&& collisionInfo.get(PITCH_SYMMETRIC).getAsJsonPrimitive().isBoolean()) {
shape.setPitchSymmetric(collisionInfo.get(PITCH_SYMMETRIC).getAsBoolean());
if (collisionInfo.has(YAW_SYMMETRIC) && collisionInfo.get(YAW_SYMMETRIC).isJsonPrimitive()
&& collisionInfo.get(YAW_SYMMETRIC).getAsJsonPrimitive().isBoolean()) {
shape.setYawSymmetric(collisionInfo.get(YAW_SYMMETRIC).getAsBoolean());
if (collisionInfo.has(ROLL_SYMMETRIC) && collisionInfo.get(ROLL_SYMMETRIC).isJsonPrimitive()
&& collisionInfo.get(ROLL_SYMMETRIC).getAsJsonPrimitive().isBoolean()) {
shape.setRollSymmetric(collisionInfo.get(ROLL_SYMMETRIC).getAsBoolean());
if (collisionInfo.has(SYMMETRIC) && collisionInfo.get(SYMMETRIC).isJsonPrimitive()
&& collisionInfo.get(SYMMETRIC).getAsJsonPrimitive().isBoolean()) {
if (collisionInfo.get(SYMMETRIC).getAsBoolean()) {
shape.setCollisionSymmetric(true);
代码示例来源:origin: apache/incubator-gobblin
/**
* Set properties for {@link JsonSchema} from a {@link JsonObject}.
* @param jsonObject
*/
private void setJsonSchemaProperties(JsonObject jsonObject) {
setColumnName(jsonObject.get(COLUMN_NAME_KEY).getAsString());
setDataType(jsonObject.get(DATA_TYPE_KEY).getAsJsonObject());
setNullable(jsonObject.has(IS_NULLABLE_KEY) && jsonObject.get(IS_NULLABLE_KEY).getAsBoolean());
setComment(getOptionalProperty(jsonObject, COMMENT_KEY));
setDefaultValue(getOptionalProperty(jsonObject, DEFAULT_VALUE_KEY));
}
}
代码示例来源:origin: apache/incubator-gobblin
/**
* Set properties for {@link JsonSchema} from a {@link JsonObject}.
* @param jsonObject
*/
private void setJsonSchemaProperties(JsonObject jsonObject) {
setColumnName(jsonObject.get(COLUMN_NAME_KEY).getAsString());
setDataType(jsonObject.get(DATA_TYPE_KEY).getAsJsonObject());
setNullable(jsonObject.has(IS_NULLABLE_KEY) && jsonObject.get(IS_NULLABLE_KEY).getAsBoolean());
setComment(getOptionalProperty(jsonObject, COMMENT_KEY));
setDefaultValue(getOptionalProperty(jsonObject, DEFAULT_VALUE_KEY));
}
内容来源于网络,如有侵权,请联系作者删除!