Example usage for com.google.gson JsonPrimitive isString

List of usage examples for com.google.gson JsonPrimitive isString

Introduction

In this page you can find the example usage for com.google.gson JsonPrimitive isString.

Prototype

public boolean isString() 

Source Link

Document

Check whether this primitive contains a String value.

Usage

From source file:xyz.dogboy.paperplane.PaperPlane.java

License:Open Source License

private Optional<JsonObject> getConfigForUploadService(UploadService service) {
    if (!this.config.has("services")) {
        return Optional.empty();
    }//from  www.ja v  a  2 s  .c om
    JsonObject services = this.config.getAsJsonObject("services");
    if (!services.has(service.getServiceId())) {
        return Optional.empty();
    }

    JsonObject config = services.getAsJsonObject(service.getServiceId());
    JsonObject finalConfig = new JsonObject();

    for (Map.Entry<String, UploadSettingType> entry : service.getNeededSettings().entrySet()) {
        if (!config.has(entry.getKey()) || !config.get(entry.getKey()).isJsonPrimitive()) {
            return Optional.empty();
        }

        JsonPrimitive setting = config.getAsJsonPrimitive(entry.getKey());
        if (!setting.isString()) {
            return Optional.empty();
        }

        try {
            finalConfig.addProperty(entry.getKey(),
                    entry.getValue().getDecoder().encode(this.secureStore, setting.getAsString()));
        } catch (GeneralSecurityException e) {
            Log.warn("Failed to decrypt secured value " + entry.getKey(), e);
        }
    }

    return Optional.of(finalConfig);
}