issue #1 添加分组管理接口-创建分组接口

This commit is contained in:
Daniel Qian
2014-08-25 17:19:27 +08:00
parent 5ddce62556
commit f57a0e4c87
17 changed files with 204 additions and 52 deletions

View File

@@ -0,0 +1,55 @@
/*
* KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved.
*
* This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended
* only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction
* arose from modification of the original source, or other redistribution of this source
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
*/
package chanjarster.weixin.util.json;
import java.lang.reflect.Type;
import chanjarster.weixin.bean.WxGroup;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
/**
*
* @author qianjia
*
*/
public class WxGroupGsonAdapter implements JsonSerializer<WxGroup>, JsonDeserializer<WxGroup> {
public JsonElement serialize(WxGroup group, Type typeOfSrc, JsonSerializationContext context) {
JsonObject json = new JsonObject();
JsonObject groupJson = new JsonObject();
groupJson.addProperty("name", group.getName());
groupJson.addProperty("id", group.getId());
groupJson.addProperty("count", group.getCount());
json.add("group", groupJson);
return json;
}
public WxGroup deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
WxGroup group = new WxGroup();
JsonObject groupJson = json.getAsJsonObject().get("group").getAsJsonObject();
if (groupJson.get("name") != null && !groupJson.get("name").isJsonNull()) {
group.setName(GsonHelper.getAsString(groupJson.get("name")));
}
if (groupJson.get("id") != null && !groupJson.get("id").isJsonNull()) {
group.setId(GsonHelper.getAsPrimitiveLong(groupJson.get("id")));
}
if (groupJson.get("count") != null && !groupJson.get("count").isJsonNull()) {
group.setCount(GsonHelper.getAsPrimitiveLong(groupJson.get("count")));
}
return group;
}
}

View File

@@ -1,6 +1,7 @@
package chanjarster.weixin.util.json;
import chanjarster.weixin.bean.WxCustomMessage;
import chanjarster.weixin.bean.WxGroup;
import chanjarster.weixin.bean.WxMassGroupMessage;
import chanjarster.weixin.bean.WxMassNews;
import chanjarster.weixin.bean.WxMassOpenIdsMessage;
@@ -20,6 +21,8 @@ public class WxGsonBuilder {
INSTANCE.registerTypeAdapter(WxMassNews.class, new WxMassNewsGsonAdapter());
INSTANCE.registerTypeAdapter(WxMassGroupMessage.class, new WxMassMessageGsonAdapter());
INSTANCE.registerTypeAdapter(WxMassOpenIdsMessage.class, new WxMassOpenIdsMessageGsonAdapter());
INSTANCE.registerTypeAdapter(WxGroup.class, new WxGroupGsonAdapter());
}
public static Gson create() {