Example usage for com.google.gson JsonObject addProperty

List of usage examples for com.google.gson JsonObject addProperty

Introduction

In this page you can find the example usage for com.google.gson JsonObject addProperty.

Prototype

public void addProperty(String property, Character value) 

Source Link

Document

Convenience method to add a char member.

Usage

From source file:ccm.pay2spawn.types.guis.HelperGuiBase.java

License:Open Source License

public void storeValue(String key, JsonObject jsonObject, Object value) {
    if (key == null || jsonObject == null)
        return;/*  ww w . jav a 2  s.  c  o  m*/
    if (value == null) {
        jsonObject.add(key, JsonNull.INSTANCE);
        return;
    }
    if (Strings.isNullOrEmpty(value.toString()))
        jsonObject.remove(key);
    else
        jsonObject.addProperty(key,
                typeMap != null && typeMap.containsKey(key) ? typeMap.get(key) + ":" + value.toString()
                        : value.toString());
}

From source file:ccm.pay2spawn.util.RewardsDB.java

License:Open Source License

public RewardsDB(File file) {
    editable = true;/*from   ww w  .  j a  va2  s  .com*/
    try {
        if (file.exists()) {
            try {
                JsonArray rootArray = JSON_PARSER.parse(new FileReader(file)).getAsJsonArray();

                for (JsonElement element : rootArray) {
                    Reward reward = new Reward(element.getAsJsonObject());
                    map.put(reward.getAmount(), reward);
                }
            } catch (Exception e) {
                Pay2Spawn.getLogger().warn("ERROR TYPE 2: There is an error in your config file.");
                e.printStackTrace();
            }
        } else {
            //noinspection ResultOfMethodCallIgnored
            file.createNewFile();
            JsonArray rootArray = new JsonArray();

            JsonObject group = new JsonObject();
            group.addProperty("name", "EXAMPLE");
            group.addProperty("amount", 2);
            group.addProperty("countdown", 10);
            group.addProperty("message", "&a[$name donated $$amount]");
            JsonArray rewards = new JsonArray();
            for (TypeBase type : TypeRegistry.getAllTypes()) {
                JsonObject element = new JsonObject();
                element.addProperty("type", type.getName());
                //noinspection unchecked
                element.add("data", JsonNBTHelper.parseNBT(type.getExample()));
                rewards.add(element);
            }
            group.add("rewards", rewards);
            rootArray.add(group);

            BufferedWriter bw = new BufferedWriter(new FileWriter(file));
            bw.write(GSON.toJson(rootArray));
            bw.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:cd.go.artifact.dummy.DummyArtifactPlugin.java

License:Apache License

@Override
public GoPluginApiResponse handle(GoPluginApiRequest request) throws UnhandledRequestTypeException {
    final RequestFromServer requestFromServer = RequestFromServer.from(request.requestName());
    try {//w w w . j ava2 s .c  om
        switch (requestFromServer) {
        case REQUEST_GET_CAPABILITIES:
            return DefaultGoPluginApiResponse.success("{}");
        case REQUEST_STORE_CONFIG_METADATA:
            return DefaultGoPluginApiResponse.success(artifactStoreMetadata());
        case REQUEST_STORE_CONFIG_VIEW:
            return DefaultGoPluginApiResponse.success(new View("/artifact-store.template.html").toJSON());
        case REQUEST_STORE_CONFIG_VALIDATE:
            return DefaultGoPluginApiResponse
                    .success(ArtifactStoreConfig.from(request.requestBody()).validate().toJSON());
        case REQUEST_PUBLISH_ARTIFACT_METADATA:
            return DefaultGoPluginApiResponse.success(ArtifactConfig.artifactConfigMetadata());
        case REQUEST_PUBLISH_ARTIFACT_VIEW:
            return DefaultGoPluginApiResponse.success(new View("/publish-artifact.template.html").toJSON());
        case REQUEST_PUBLISH_ARTIFACT_VALIDATE:
            return DefaultGoPluginApiResponse
                    .success(ArtifactConfig.from(request.requestBody()).validate().toJSON());
        case REQUEST_FETCH_ARTIFACT_METADATA:
            return DefaultGoPluginApiResponse.success(FetchArtifact.metadata());
        case REQUEST_FETCH_ARTIFACT_VIEW:
            return DefaultGoPluginApiResponse.success(new View("/fetch-artifact.template.html").toJSON());
        case REQUEST_FETCH_ARTIFACT_VALIDATE:
            return DefaultGoPluginApiResponse
                    .success(FetchArtifact.from(request.requestBody()).validate().toJSON());
        case REQUEST_PUBLISH_ARTIFACT:
            return publishArtifact(PublishArtifactRequest.fromJSON(request.requestBody()));
        case REQUEST_FETCH_ARTIFACT:
            return fetchArtifact(FetchArtifactRequest.fromJSON(request.requestBody()));
        case REQUEST_GET_PLUGIN_ICON:
            JsonObject jsonObject = new JsonObject();
            jsonObject.addProperty("content_type", "image/jpg");
            jsonObject.addProperty("data",
                    Base64.getEncoder().encodeToString(ResourceReader.readBytes("/icon.jpg")));
            return DefaultGoPluginApiResponse.success(jsonObject.toString());
        default:
            throw new RuntimeException("Error while executing request" + request.requestName());
        }
    } catch (Exception e) {
        LOG.error("Error while executing request " + request.requestName(), e);
        throw new RuntimeException(e);
    }
}

From source file:cd.go.authentication.ldap.executor.GetAuthConfigViewExecutor.java

License:Apache License

@Override
public GoPluginApiResponse execute() throws Exception {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("template", Util.readResource("/auth_config.template.html"));
    DefaultGoPluginApiResponse defaultGoPluginApiResponse = new DefaultGoPluginApiResponse(200,
            GSON.toJson(jsonObject));//  ww w. j  a v a2 s . c  o m
    return defaultGoPluginApiResponse;
}

From source file:cd.go.authentication.ldap.executor.GetPluginIconExecutor.java

License:Apache License

@Override
public GoPluginApiResponse execute() throws Exception {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("content_type", "image/png");
    jsonObject.addProperty("data",
            Base64.getEncoder().encodeToString(Util.readResourceBytes("/gocd_72_72_icon.png")));
    DefaultGoPluginApiResponse defaultGoPluginApiResponse = new DefaultGoPluginApiResponse(200,
            GSON.toJson(jsonObject));// ww w. j  a  va  2  s  .  c  o  m
    return defaultGoPluginApiResponse;

}

From source file:cd.go.authentication.passwordfile.executor.GetAuthConfigViewExecutor.java

License:Apache License

@Override
public GoPluginApiResponse execute() throws Exception {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("template", Util.readResource("/auth-config.template.html"));
    DefaultGoPluginApiResponse defaultGoPluginApiResponse = new DefaultGoPluginApiResponse(200,
            GSON.toJson(jsonObject));// www  . j  a va2  s  .  c o m
    return defaultGoPluginApiResponse;
}

From source file:cd.go.authentication.passwordfile.executor.GetPluginIconExecutor.java

License:Apache License

@Override
public GoPluginApiResponse execute() throws Exception {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("content_type", getContentType());
    jsonObject.addProperty("data", Base64.encodeBase64String(Util.readResourceBytes(getIcon())));
    DefaultGoPluginApiResponse defaultGoPluginApiResponse = new DefaultGoPluginApiResponse(200,
            GSON.toJson(jsonObject));/*from  w ww .j a  v  a2  s .c  o  m*/
    return defaultGoPluginApiResponse;

}

From source file:cd.go.contrib.elasticagents.docker.executors.GetPluginSettingsIconExecutor.java

License:Apache License

@Override
public GoPluginApiResponse execute() throws Exception {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("content_type", "image/svg+xml");
    jsonObject.addProperty("data", Base64.encodeBase64String(Util.readResourceBytes("/docker-plain.svg")));
    DefaultGoPluginApiResponse defaultGoPluginApiResponse = new DefaultGoPluginApiResponse(200,
            GSON.toJson(jsonObject));/*from www.  j ava  2  s . co m*/
    return defaultGoPluginApiResponse;

}

From source file:cd.go.contrib.elasticagents.docker.executors.GetProfileViewExecutor.java

License:Apache License

@Override
public GoPluginApiResponse execute() throws Exception {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("template", Util.readResource("/profile.template.html"));
    DefaultGoPluginApiResponse defaultGoPluginApiResponse = new DefaultGoPluginApiResponse(200,
            GSON.toJson(jsonObject));//from www.j ava2  s. co m
    return defaultGoPluginApiResponse;
}

From source file:cd.go.contrib.elasticagents.docker.executors.GetViewRequestExecutor.java

License:Apache License

@Override
public GoPluginApiResponse execute() throws Exception {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("template", Util.readResource("/plugin-settings.template.html"));
    DefaultGoPluginApiResponse defaultGoPluginApiResponse = new DefaultGoPluginApiResponse(200,
            GSON.toJson(jsonObject));/*from w  w w  . ja v a  2  s . c o  m*/
    return defaultGoPluginApiResponse;
}