@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()); }
private static void addPatternListToSource(JsonObject sourceObject, String rule, List<String> patternList) { if (!patternList.isEmpty()) { JsonArray ruleArray; if (sourceObject.has(rule)) { ruleArray = sourceObject.get(rule).getAsJsonArray(); } else { ruleArray = new JsonArray(); sourceObject.add(rule, ruleArray); } for (String pattern : patternList) { ruleArray.add(pattern); } } }
@Override public JsonElement merge(final JsonElement first, final JsonElement second) { if (first.isJsonNull()) { return second; } if (second.isJsonNull()) { return first; } if (first.isJsonObject() && second.isJsonObject()) { JsonObject result = new JsonObject(); first.getAsJsonObject().entrySet().forEach(entry -> result.add(entry.getKey(), entry.getValue())); second.getAsJsonObject().entrySet().forEach(entry -> result.add(entry.getKey(), entry.getValue())); return result; } if (first.isJsonArray() && second.isJsonArray()) { JsonArray result = new JsonArray(); first.getAsJsonArray().forEach(result::add); second.getAsJsonArray().forEach(result::add); return result; } throw new IllegalArgumentException("Could not merge " + first + " and " + second); }
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>);
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(); }
private void addEnvironment(Properties envProps) { JsonArray containerEnv = new JsonArray(); Enumeration keys = envProps.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); String value = envProps.getProperty(key); if (value == null) { value = ""; } containerEnv.add(key + "=" + value); } createConfig.add("Env", containerEnv); }
JsonObject child = new JsonObject(); //(obj.path+'.'+ItemName); LocationData loc = lexer.location.copy(); obj.add(itemName, child); next(); readObject(child, false); case Boolean : JsonPrimitive v = new JsonPrimitive(Boolean.valueOf(itemValue)); obj.add(itemName, v); map.put(v, lexer.location.copy()); break; case String: v = new JsonPrimitive(itemValue); obj.add(itemName, v); map.put(v, lexer.location.copy()); break; break; case Array: JsonArray arr = new JsonArray(); // (obj.path+'.'+ItemName); loc = lexer.location.copy(); obj.add(itemName, arr);
switch (itemType) { case Object: JsonObject obj = new JsonObject(); // (arr.path+'['+inttostr(i)+']'); LocationData loc = lexer.location.copy(); arr.add(obj); next(); readObject(obj, false); case String: JsonPrimitive v = new JsonPrimitive(itemValue); arr.add(v); map.put(v, lexer.location.copy()); break; case Number: v = new JsonPrimitive(new BigDecimal(itemValue)); arr.add(v); map.put(v, lexer.location.copy()); break; break; case Array: JsonArray child = new JsonArray(); // (arr.path+'['+inttostr(i)+']'); loc = lexer.location.copy(); arr.add(child);
@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()); }
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()); } }
@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; } }