Refine search
@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()); }
@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()); }
@Test public void shouldIgnoreWhenJsonHasUnknownElements() { Map<String,T> examples = getExamples(); for(Map.Entry<String,T> example : examples.entrySet()) { T value = example.getValue(); JsonObject jsonObject = (JsonObject)gson.toJsonTree(value); jsonObject.add("extraProperty", new JsonPrimitive("This is not part of message type")); String json = gson.toJson(jsonObject); T deserializedValue = (T)gson.fromJson(json,value.getClass()); assertThat(String.format("Example %s - Deserialized value should equal to value before serialization", example.getKey()), deserializedValue, is(value)); } }
switch (itemType) { case Object: JsonObject obj = new JsonObject(); // (arr.path+'['+inttostr(i)+']'); LocationData loc = lexer.location.copy(); arr.add(obj); break; 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());
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; }
@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 PackageGenerator file(String name) { JsonArray files = object.getAsJsonArray("files"); if (files == null) { files = new JsonArray(); object.add("files", files); } files.add(new JsonPrimitive(name)); return this; }
switch (itemType) { case Object: JsonObject obj = new JsonObject(); // (arr.path+'['+inttostr(i)+']'); LocationData loc = lexer.location.copy(); arr.add(obj); break; case String: JsonPrimitive v = new JsonPrimitive(itemValue); arr.add(v); if (map != null) break; case Number: v = new JsonPrimitive(new BigDecimal(itemValue)); arr.add(v); if (map != null)
@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); }
public JsonElement serialize(WxMpMassOpenIdsMessage message, Type typeOfSrc, JsonSerializationContext context) { JsonObject messageJson = new JsonObject(); toUsers.add(new JsonPrimitive(openId)); messageJson.add("touser", toUsers); JsonObject sub = new JsonObject(); sub.addProperty("media_id", message.getMediaId()); messageJson.add(WxConsts.MASS_MSG_NEWS, sub); JsonObject sub = new JsonObject(); sub.addProperty("content", message.getContent()); messageJson.add(WxConsts.MASS_MSG_TEXT, sub);
public PackageGenerator file(String name) { JsonArray files = object.getAsJsonArray("files"); if (files == null) { files = new JsonArray(); object.add("files", files); } files.add(new JsonPrimitive(name)); return this; }
@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; } }
@Override public JsonElement serialize(EntityData.Entity src, Type typeOfSrc, JsonSerializationContext context) { JsonObject result = new JsonObject(); if (src.hasId()) { result.addProperty("id", src.getId()); } if (src.hasParentPrefab() && !src.getParentPrefab().isEmpty()) { result.addProperty("parentPrefab", src.getParentPrefab()); } if (src.hasAlwaysRelevant()) { result.addProperty("alwaysRelevant", src.getAlwaysRelevant()); } if (src.hasOwner()) { result.addProperty("owner", src.getOwner()); } for (EntityData.Component component : src.getComponentList()) { result.add(component.getType(), context.serialize(component)); } if (src.getRemovedComponentCount() > 0) { JsonArray removedComponentArray = new JsonArray(); for (String removedComponent : src.getRemovedComponentList()) { removedComponentArray.add(new JsonPrimitive(removedComponent)); } result.add("removedComponent", removedComponentArray); } return result; }
public final class MYInterfaceAdapter implements JsonDeserializer<MyInterface>, JsonSerializer<MyInterface> { private static final String PROP_NAME = "myClass"; @Override public MyInterface deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { try { String classPath = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); Class<MyInterface> cls = (Class<MyInterface>) Class.forName(classPath); return (MyInterface) context.deserialize(json, cls); } catch (ClassNotFoundException e) { e.printStackTrace(); } return null; } @Override public JsonElement serialize(MyInterface src, Type typeOfSrc, JsonSerializationContext context) { // note : won't work, you must delegate this JsonObject jo = context.serialize(src).getAsJsonObject(); String classPath = src.getClass().getName(); jo.add(PROP_NAME, new JsonPrimitive(classPath)); return jo; } }
@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();
JsonObject entity = new JsonObject(); JsonObject details = new JsonObject(); JsonObject rpClaims = new JsonObject(); rpClaims.addProperty("redirect_user", true); rpClaims.addProperty("ticket", ticketValue); JsonArray f = new JsonArray(); for (String format : claim.getClaimTokenFormat()) { f.add(new JsonPrimitive(format)); c.add("claim_token_format", f); JsonArray i = new JsonArray(); for (String issuer : claim.getIssuer()) { i.add(new JsonPrimitive(issuer)); c.add("issuer", i); req.add(c); rpClaims.add("required_claims", req); details.add("requesting_party_claims", rpClaims); entity.add("error_details", details);
private JsonArray tableToJson(Table<Integer, Integer, Object> table, Gson gson) { JsonArray jsonTable = new JsonArray(); table.rowMap().forEach((rk, r) -> { if (rk == 0) { return; } JsonObject jsonRow = new JsonObject(); table.columnMap().forEach((ck, c) -> { String key = String.valueOf(table.get(0, ck)).toLowerCase(); Object value = table.get(rk, ck); jsonRow.add(key, gson.toJsonTree(value)); }); jsonTable.add(jsonRow); }); JsonObject jsonRoot = new JsonObject(); if (file != null) { jsonRoot.add("file", new JsonPrimitive(file.toString())); } return jsonTable; } }
try { for (int i = 0; i < numMsg; ++i) { JsonObject object = new JsonObject(); object.addProperty("key1", UUID.randomUUID().toString()); object.addProperty("key2", rand.nextInt()); element2.add(new JsonPrimitive(rand.nextInt(100))); element2.add(new JsonPrimitive(rand.nextInt(100))); element2.add(new JsonPrimitive(rand.nextInt(100))); object.add("key5", element2); JsonObject element3 = new JsonObject(); element3.addProperty("key61", rand.nextDouble()); element3.addProperty("key62", rand.nextDouble()); object.add("key6", element3);
private <S> void writeObject(S value, JsonWriter out) throws IOException { if (value != null) { JsonObject jsonObject = new JsonObject(); jsonObject.add(OBJECT_TYPE, new JsonPrimitive(value.getClass().getName())); TypeAdapter<S> delegate = (TypeAdapter<S>) this.gson.getDelegateAdapter(this.factory, TypeToken.get(value.getClass())); jsonObject.add(OBJECT_DATA, delegate.toJsonTree(value)); Streams.write(jsonObject, out); } else { out.nullValue(); } }
@Override public JsonElement serialize(WxCpUser user, Type typeOfSrc, JsonSerializationContext context) { JsonObject o = new JsonObject(); if (user.getUserId() != null) { o.addProperty("userid", user.getUserId()); JsonArray jsonArray = new JsonArray(); for (Integer departId : user.getDepartIds()) { jsonArray.add(new JsonPrimitive(departId)); o.add("department", jsonArray); JsonArray attrsJsonArray = new JsonArray(); for (WxCpUser.Attr attr : user.getExtAttrs()) { JsonObject attrJson = new JsonObject(); attrJson.addProperty("name", attr.getName()); attrJson.addProperty("value", attr.getValue()); attrsJsonArray.add(attrJson); JsonObject attrsJson = new JsonObject(); attrsJson.add("attrs", attrsJsonArray); o.add("extattr", attrsJson);