List of usage examples for com.google.gson JsonObject JsonObject
JsonObject
From source file:ccm.pay2spawn.util.JsonNBTHelper.java
License:Open Source License
public static JsonObject fixNulls(JsonObject object) { JsonObject newObject = new JsonObject(); for (Map.Entry<String, JsonElement> entry : object.entrySet()) newObject.add(entry.getKey(), fixNulls(entry.getValue())); return newObject; }
From source file:ccm.pay2spawn.util.RewardsDB.java
License:Open Source License
public RewardsDB(File file) { editable = true;/*from w w w.java 2s .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 ww . j a v a 2 s . c o m*/ 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));//from ww w . j a v a2 s . co 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));//from w w w .j av a 2 s.com 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));//from ww w . j ava 2s.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));// w ww. ja v a 2 s .co 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 w ww. j a v a 2 s . c om 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 w w w . j av a2 s . c o 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. j a v a 2 s . c om*/ return defaultGoPluginApiResponse; }