Example usage for com.google.gson JsonElement getAsBoolean

List of usage examples for com.google.gson JsonElement getAsBoolean

Introduction

In this page you can find the example usage for com.google.gson JsonElement getAsBoolean.

Prototype

public boolean getAsBoolean() 

Source Link

Document

convenience method to get this element as a boolean value.

Usage

From source file:org.miness.jloglib.JLLUtils.java

License:Open Source License

/**
 * Loads the specified settings from a settings file (JSON data).<br />
 * <b>Attention</b>: By calling this method, the current settings will be completely overwritten!<br />
 * @param path the path to the file to load settings from.
 *//*from   w ww . ja v a2 s. c o m*/
public void loadSettings(String path) {
    try {
        Scanner scanner = new Scanner(new File(path)).useDelimiter("\\Z");
        String settingsString = scanner.next();
        JsonObject settingsObjOuter = new JsonParser().parse(settingsString).getAsJsonObject();
        JsonObject settingsObjInner = settingsObjOuter.get("jll_settings").getAsJsonObject();
        Set<Map.Entry<String, JsonElement>> settingsSet = settingsObjInner.entrySet();
        for (Map.Entry<String, JsonElement> e : settingsSet) {
            String key = e.getKey();
            JsonElement value = e.getValue();
            if (key.equals("loggingEnabled")) {
                settings.enableLogging(value.getAsBoolean());
            } else if (key.equals("logLevel")) {
                settings.setLogLevel(Enum.valueOf(LogLevel.class, value.getAsString()));
            } else if (key.equals("allowSubLogLevels")) {
                settings.allowSubLogLevels(value.getAsBoolean());
            } else if (key.equals("logTarget")) {
                settings.setLogTarget(Enum.valueOf(LogTarget.class, value.getAsString()));
            } else if (key.equals("logFile")) {
                settings.setLogFile(value.getAsString());
            } else if (key.equals("printDate")) {
                settings.printDate(value.getAsBoolean());
            } else if (key.equals("dateFormat")) {
                settings.setDateFormat(Enum.valueOf(LogDateFormat.class, value.getAsString()));
            } else if (key.equals("printTime")) {
                settings.printTime(value.getAsBoolean());
            } else if (key.equals("timeFormat")) {
                settings.setTimeFormat(Enum.valueOf(LogDateFormat.class, value.getAsString()));
            } else if (key.equals("delimiter")) {
                settings.setDelimiter(value.getAsString());
            } else if (key.equals("applicationName")) {
                settings.setApplicationName(value.getAsString());
            } else if (key.equals("printApplicationName")) {
                settings.printApplicationName(value.getAsBoolean());
            }
        }
    } catch (FileNotFoundException e) {
        printInternalError("Reason: The specified settings file cannot be found.");
    }
}

From source file:org.mitre.provenance.client.RESTProvenanceClient.java

License:Apache License

public boolean dominates(PrivilegeClass a, PrivilegeClass b) throws ProvenanceClientException {
    Builder r = getRequestBuilderForPath(PRIVILEGE_PATH + a.getId() + "/" + b.getId());
    Response response = r.get();//from   w ww.  j  av a 2s.c om
    Gson g = new GsonBuilder().create();
    String txt = response.readEntity(String.class);
    JsonElement elem = g.fromJson(txt, JsonElement.class);
    if (elem.isJsonPrimitive())
        return elem.getAsBoolean();
    throw new ProvenanceClientException(txt);
}

From source file:org.mitre.util.JsonUtils.java

License:Apache License

/**
 * Gets the value of the given member as a boolean, null if it doesn't exist
 *///  ww w. j  a v  a  2 s.com
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;
    }
}

From source file:org.mule.modules.servicesource.ApiResponseDeserealizer.java

License:Open Source License

private void deserealizeSuccess(JsonObject json, ApiResponse<Object> response) {
    JsonElement element = json.get("success");
    response.setSuccess(element == null ? true : element.getAsBoolean());
}

From source file:org.opendolphin.core.comm.JsonCodec.java

License:Apache License

private boolean booleanOrFalse(JsonElement element) {
    if (element.isJsonNull()) {
        return false;
    }// ww  w.java  2  s. com
    return element.getAsBoolean();
}

From source file:org.openhab.binding.russound.internal.rio.models.RioFavoriteSerializer.java

License:Open Source License

/**
 * Overridden to simply read the id/valid/name elements and create a {@link RioFavorite}
 *
 * @param elm the {@link JsonElement} to read from
 * @param type the type//from w ww.j a  v  a 2s.c  om
 * @param context the serialization context
 */
@Override
public RioFavorite deserialize(JsonElement elm, Type type, JsonDeserializationContext context)
        throws JsonParseException {
    final JsonObject jo = (JsonObject) elm;

    final JsonElement id = jo.get("id");
    final JsonElement valid = jo.get("valid");
    final JsonElement name = jo.get("name");

    return new RioFavorite((id == null ? -1 : id.getAsInt()), (valid == null ? false : valid.getAsBoolean()),
            (name == null ? null : name.getAsString()));
}

From source file:org.openhab.binding.russound.internal.rio.models.RioPresetSerializer.java

License:Open Source License

/**
 * Overridden to simply read the id/valid/name elements and create a {@link RioPreset}. Please note that
 * the bank/bankPreset are calculated fields from the ID and do not need to be read.
 *
 * @param elm the {@link JsonElement} to read from
 * @param type the type/*from  w ww  . ja  v  a  2  s  .  c  o  m*/
 * @param context the serialization context
 */
@Override
public RioPreset deserialize(JsonElement elm, Type type, JsonDeserializationContext context)
        throws JsonParseException {
    final JsonObject jo = (JsonObject) elm;
    final JsonElement id = jo.get("id");
    final JsonElement valid = jo.get("valid");
    final JsonElement name = jo.get("name");

    return new RioPreset((id == null ? -1 : id.getAsInt()), (valid == null ? false : valid.getAsBoolean()),
            (name == null ? null : name.getAsString()));
}

From source file:org.openhab.binding.unifi.internal.api.util.UniFiClientDeserializer.java

License:Open Source License

@Override
public UniFiClient deserialize(JsonElement json, Type type, JsonDeserializationContext context)
        throws JsonParseException {
    JsonObject jsonObject = json.getAsJsonObject();
    JsonElement isWiredElement = jsonObject.get(PROPERTY_IS_WIRED);
    // mgb: if the "is_wired "property is missing, the client is unknown
    if (isWiredElement == null) {
        return context.deserialize(json, UniFiUnknownClient.class);
    }/*from www . j  a  va2  s  .c om*/
    boolean isWired = isWiredElement.getAsBoolean();
    if (isWired) {
        return context.deserialize(json, UniFiWiredClient.class);
    }
    return context.deserialize(json, UniFiWirelessClient.class);
}

From source file:org.openqa.selendroid.server.model.AndroidWebElement.java

License:Apache License

public boolean isDisplayed() {
    JsonElement result = (JsonElement) driver.executeAtom(AndroidAtoms.IS_DISPLAYED, this);
    if (result != null) {
        return result.getAsBoolean();
    }/*from   w  ww .ja va2s .co  m*/
    return false;
}

From source file:org.qcert.runtime.BinaryOperators.java

License:Apache License

public static JsonElement and(JsonElement e1, JsonElement e2) {
    return new JsonPrimitive(e1.getAsBoolean() && e2.getAsBoolean());
}