@Override public String getFormattedMessage(String message) { final JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("message", message); return GSON.toJson(jsonObject); } }
public ContainerHostConfig restartPolicy(String name, int retry) { if (name != null) { JsonObject policy = new JsonObject(); policy.addProperty("Name", name); policy.addProperty("MaximumRetryCount", retry); startConfig.add("RestartPolicy", policy); } return this; }
public String toJson() { JsonObject details = new JsonObject(); details.addProperty(FIELD_LEVEL, level.toString()); JsonArray conditionResults = new JsonArray(); for (EvaluatedCondition condition : this.conditions) { conditionResults.add(toJson(condition)); } details.add("conditions", conditionResults); details.addProperty(FIELD_IGNORED_CONDITIONS, ignoredConditions); return details.toString(); }
@Override public void tagRemoveUsers(String tagId, List<String> userIds) throws WxErrorException { String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/deltagusers"; JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("tagid", tagId); JsonArray jsonArray = new JsonArray(); for (String userId : userIds) { jsonArray.add(new JsonPrimitive(userId)); } jsonObject.add("userlist", jsonArray); post(url, jsonObject.toString()); }
/** * Example to writeJson using TreeModel */ private static void writeJson() throws IOException { JsonObject rootObject = new JsonObject(); rootObject.addProperty("message", "Hi"); JsonObject childObject = new JsonObject(); childObject.addProperty("name", "World!"); rootObject.add("place", childObject); Gson gson = new Gson(); String json = gson.toJson(rootObject); System.out.println(json); // print "{"message":"Hi","place":{"name":"World!"}}" } }
private JsonObject mapToJsonObject(Map<String, String> configuration) { final JsonObject properties = new JsonObject(); for (Map.Entry<String, String> entry : configuration.entrySet()) { properties.addProperty(entry.getKey(), entry.getValue()); } return properties; }
public static String toJson(EvaluatedQualityGate gate) { JsonObject details = new JsonObject(); details.addProperty(FIELD_LEVEL, gate.getStatus().name()); JsonArray conditionResults = new JsonArray(); for (EvaluatedCondition condition : gate.getEvaluatedConditions()) { conditionResults.add(toJson(condition)); } details.add("conditions", conditionResults); details.addProperty(FIELD_IGNORED_CONDITIONS, gate.hasIgnoredConditionsOnSmallChangeset()); return details.toString(); }
JsonObject obj = new JsonObject(); JsonObject payerReg = new JsonObject(); payerReg.addProperty("crc","aas22"); payerReg.addProperty("payerDevManufacturer","Samsung"); obj.add("payerReg",payerReg); /*json/* {"payerReg":{"crc":"aas22","payerDevManufacturer":"Samsung"}} /*json*/
private JsonObject mapToJsonObject(Map<String, String> configuration) { final JsonObject properties = new JsonObject(); for (Map.Entry<String, String> entry : configuration.entrySet()) { properties.addProperty(entry.getKey(), entry.getValue()); } return properties; }
@Override public void tagAddUsers(String tagId, List<String> userIds, List<String> partyIds) throws WxErrorException { String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/addtagusers"; JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("tagid", tagId); if (userIds != null) { JsonArray jsonArray = new JsonArray(); for (String userId : userIds) { jsonArray.add(new JsonPrimitive(userId)); } jsonObject.add("userlist", jsonArray); } if (partyIds != null) { JsonArray jsonArray = new JsonArray(); for (String userId : partyIds) { jsonArray.add(new JsonPrimitive(userId)); } jsonObject.add("partylist", jsonArray); } post(url, jsonObject.toString()); }
public static JsonObject createColumnJson(String columnName, boolean isNullable, JsonElementConversionFactory.Type columnType) { JsonObject columnJson = new JsonObject(); columnJson.addProperty("columnName", columnName); columnJson.addProperty("isNullable", isNullable); JsonObject typeJson = new JsonObject(); typeJson.addProperty("type", columnType.toString()); columnJson.add("dataType", typeJson); return columnJson; } }
private JsonObject jobIdentifierJson(JobIdentifier jobIdentifier) { JsonObject jobIdentifierJson = new JsonObject(); jobIdentifierJson.addProperty("pipeline_name", jobIdentifier.getPipelineName()); jobIdentifierJson.addProperty("pipeline_label", jobIdentifier.getPipelineLabel()); jobIdentifierJson.addProperty("pipeline_counter", jobIdentifier.getPipelineCounter()); jobIdentifierJson.addProperty("stage_name", jobIdentifier.getStageName()); jobIdentifierJson.addProperty("stage_counter", jobIdentifier.getStageCounter()); jobIdentifierJson.addProperty("job_name", jobIdentifier.getBuildName()); jobIdentifierJson.addProperty("job_id", jobIdentifier.getBuildId()); return jobIdentifierJson; }
@Override protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) { response.setContentType("application/jrd+json"); HttpStatus code = (HttpStatus) model.get(HttpCodeView.CODE); if (code == null) { code = HttpStatus.OK; // default to 200 } response.setStatus(code.value()); try { String resource = (String)model.get("resource"); String issuer = (String)model.get("issuer"); JsonObject obj = new JsonObject(); obj.addProperty("subject", resource); JsonArray links = new JsonArray(); JsonObject link = new JsonObject(); link.addProperty("rel", "http://openid.net/specs/connect/1.0/issuer"); link.addProperty("href", issuer); links.add(link); obj.add("links", links); Writer out = response.getWriter(); gson.toJson(obj, out); } catch (IOException e) { logger.error("IOException in JsonEntityView.java: ", e); } }
private void createPayload(String source) { JsonObject jsonObject = new JsonObject(); JsonObject innerObj = new JsonObject(); innerObj.addProperty("lang", String.valueOf(scriptLanguage).toLowerCase()); innerObj.addProperty("source", source); jsonObject.add("script", innerObj); payload = jsonObject; }
private JsonObject jobIdentifierJson(JobIdentifier jobIdentifier) { JsonObject jobIdentifierJson = new JsonObject(); jobIdentifierJson.addProperty("pipeline_name", jobIdentifier.getPipelineName()); jobIdentifierJson.addProperty("pipeline_label", jobIdentifier.getPipelineLabel()); jobIdentifierJson.addProperty("pipeline_counter", jobIdentifier.getPipelineCounter()); jobIdentifierJson.addProperty("stage_name", jobIdentifier.getStageName()); jobIdentifierJson.addProperty("stage_counter", jobIdentifier.getStageCounter()); jobIdentifierJson.addProperty("job_name", jobIdentifier.getBuildName()); jobIdentifierJson.addProperty("job_id", jobIdentifier.getBuildId()); return jobIdentifierJson; } }
protected JsonObject convertToJson(WxMenu.WxMenuButton button) { JsonObject buttonJson = new JsonObject(); buttonJson.addProperty("type", button.getType()); buttonJson.addProperty("name", button.getName()); buttonJson.addProperty("key", button.getKey()); buttonJson.addProperty("url", button.getUrl()); if (button.getSubButtons() != null && button.getSubButtons().size() > 0) { JsonArray buttonArray = new JsonArray(); for (WxMenu.WxMenuButton sub_button : button.getSubButtons()) { buttonArray.add(convertToJson(sub_button)); } buttonJson.add("sub_button", buttonArray); } return buttonJson; }
JsonObject innerObject = new JsonObject(); innerObject.addProperty("name", "john"); JsonObject jsonObject = new JsonObject(); jsonObject.add("publisher", innerObject);
private void generateResponseForIsBackupFinishedAPI(ServletResponse response) { response.setContentType("application/json"); JsonObject json = new JsonObject(); json.addProperty("is_backing_up", backupService.isBackingUp()); try { response.getWriter().print(json); } catch (IOException e) { LOGGER.error("General IOException: {}", e.getMessage()); } }
/** * Create a JSON specification which can be used to in a Docker API request as the 'PortBindings' part * for creating container. * * @return 'PortBindings' object or null if no port mappings are used. */ JsonObject toDockerPortBindingsJson() { Map<String, Integer> portMap = getContainerPortToHostPortMap(); if (!portMap.isEmpty()) { JsonObject portBindings = new JsonObject(); Map<String, String> bindToMap = getBindToHostMap(); for (Map.Entry<String, Integer> entry : portMap.entrySet()) { String containerPortSpec = entry.getKey(); Integer hostPort = entry.getValue(); JsonObject o = new JsonObject(); o.addProperty("HostPort", hostPort != null ? hostPort.toString() : ""); if (bindToMap.containsKey(containerPortSpec)) { o.addProperty("HostIp", bindToMap.get(containerPortSpec)); } JsonArray array = new JsonArray(); array.add(o); portBindings.add(containerPortSpec, array); } return portBindings; } else { return null; } }
String createAgentRequestBody(String autoRegisterKey, String environment, Map<String, String> configuration, JobIdentifier jobIdentifier) { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("auto_register_key", autoRegisterKey); jsonObject.add("properties", mapToJsonObject(configuration)); jsonObject.addProperty("environment", environment); jsonObject.add("job_identifier", jobIdentifierJson(jobIdentifier)); return GSON.toJson(jsonObject); }