Example usage for com.google.gson JsonPrimitive getAsString

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

Introduction

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

Prototype

@Override
public String getAsString() 

Source Link

Document

convenience method to get this element as a String.

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();
    }/*w ww  .  ja  va  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);
}