@Override public String getFormattedMessage(String message) { final JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("message", message); return GSON.toJson(jsonObject); } }
JsonObject innerObject = new JsonObject(); innerObject.addProperty("name", "john"); JsonObject jsonObject = new JsonObject(); jsonObject.add("publisher", innerObject);
@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()); }
@Override public void print(Collection<TableModel> models) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); JsonObject jsonRoot = new JsonObject(); if (file != null) { jsonRoot.add("file", new JsonPrimitive(file.toString())); } models.forEach(model -> { jsonRoot.add(model.name().toLowerCase(), tableToJson(model.table(), gson)); }); gson.toJson(jsonRoot, out); }
Vertx vertx = Vertx.newVertx(); EventBus eventBus = vertx.eventBus() HttpServer server = vertx.createHttpServer(); JsonArray permitted = new JsonArray(); permitted.add(new JsonObject()); SockJSServer sockJSServer = new DefaultSockJSServer(vertx, server); sockJSServer.bridge(new JsonObject().putString("prefix", "/pusher"), permitted, permitted); server.listen(<some port>);
@Override public JsonElement serialize(List<PipelineConfigs> src, Type typeOfSrc, JsonSerializationContext context) { JsonObject serialized = new JsonObject(); for (PipelineConfigs group : src) { final List<PipelineConfig> pipelines = group.getPipelines(); if (!pipelines.isEmpty()) { List<CaseInsensitiveString> pipelineNames = pipelines.stream().map(PipelineConfig::name).collect(Collectors.toList()); serialized.add(group.getGroup(), context.serialize(pipelineNames)); } } return serialized; } }
@Override public void userDelete(String[] userids) throws WxErrorException { String url = "https://qyapi.weixin.qq.com/cgi-bin/user/batchdelete"; JsonObject jsonObject = new JsonObject(); JsonArray jsonArray = new JsonArray(); for (int i = 0; i < userids.length; i++) { jsonArray.add(new JsonPrimitive(userids[i])); } jsonObject.add("useridlist", 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!"}}" } }
public JsonObject toJsonObject() { JsonObject sortDefinition = new JsonObject(); if (order != null) { sortDefinition.add("order", new JsonPrimitive(order.toString())); } if (missing != null) { sortDefinition.add("missing", new JsonPrimitive(missing.toString())); } if (unmapped != null) { sortDefinition.add("ignore_unmapped", new JsonPrimitive(unmapped)); } if(unmappedType != null) { sortDefinition.add("unmapped_type", new JsonPrimitive(unmappedType)); } JsonObject sortObject = new JsonObject(); sortObject.add(field, sortDefinition); return sortObject; }
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 JsonElement serialize(PipelinesDataResponse src, Type typeOfSrc, JsonSerializationContext context) { JsonObject serialized = new JsonObject(); serialized.add("pipelines", context.serialize(src.getPipelineConfigs(), GROUPS_TYPE)); return serialized; } }
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(); }
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*/
@Override public void write(JsonWriter out, R value) throws IOException { Class<?> srcType = value.getClass(); String label = subtypeToLabel.get(srcType); @SuppressWarnings("unchecked") // registration requires that subtype extends T TypeAdapter<R> delegate = (TypeAdapter<R>) subtypeToDelegate.get(srcType); if (delegate == null) { throw new JsonParseException("cannot serialize " + srcType.getName() + "; did you forget to register a subtype?"); } JsonObject jsonObject = delegate.toJsonTree(value).getAsJsonObject(); if (jsonObject.has(typeFieldName) && !srcType.getSimpleName().equals("OldInput")) { throw new JsonParseException("cannot serialize " + srcType.getName() + " because it already defines a field named " + typeFieldName); } JsonObject clone = new JsonObject(); if (!srcType.getSimpleName().equals("OldInput")) { clone.add(typeFieldName, new JsonPrimitive(label)); } for (Map.Entry<String, JsonElement> e : jsonObject.entrySet()) { clone.add(e.getKey(), e.getValue()); } Streams.write(clone, out); } }.nullSafe();
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; }
private void addFilters(Builder builder, String... filter) { if (filter.length > 0) { if (filter.length % 2 != 0) { throw new IllegalArgumentException("Filters must be given as key value pairs and not " + Arrays.asList(filter)); } JsonObject filters = new JsonObject(); for (int i = 0; i < filter.length; i +=2) { JsonArray value = new JsonArray(); value.add(filter[i+1]); filters.add(filter[i],value); } builder.p("filters",filters.toString()); } }
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; }
@Override public JsonElement serialize(RelativeTime relativeTime, Type type, JsonSerializationContext jsonSerializationContext) { JsonObject jsonObject = new JsonObject(); jsonObject.add("value", new JsonPrimitive(relativeTime.getValue())); jsonObject.add("unit", new JsonPrimitive(relativeTime.getUnit().name().toLowerCase())); return jsonObject; } }
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()); } }
@Override public JsonElement serialize(Filters src, Type typeOfSrc, JsonSerializationContext context) { final JsonObject result = new JsonObject(); final JsonArray viewFilters = new JsonArray(); for (DashboardFilter f : src.filters()) { viewFilters.add(context.serialize(f, DashboardFilter.class)); } result.add(KEY_FILTERS, viewFilters); return result; } }