1.WxMenuRule增加language字段

2.更改了WxMenu的toJson方法使menurule转换成正确的字符串
3.WxMenuTest中增加了相应的测试用例
This commit is contained in:
miller
2016-02-15 16:54:54 +08:00
parent d253bdeba4
commit b805a9967c
3 changed files with 79 additions and 12 deletions

View File

@@ -8,9 +8,6 @@
*/
package me.chanjar.weixin.common.util.json;
import java.lang.reflect.Type;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
@@ -19,9 +16,10 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import me.chanjar.weixin.common.bean.WxMenu;
import java.lang.reflect.Type;
/**
*
* @author Daniel Qian
@@ -40,8 +38,7 @@ public class WxMenuGsonAdapter implements JsonSerializer<WxMenu>, JsonDeserializ
json.add("button", buttonArray);
if (menu.getMatchRule() != null) {
Gson gson = new Gson();
json.add("matchrule", gson.toJsonTree(menu.getMatchRule()));
json.add("matchrule", convertToJson(menu.getMatchRule()));
}
return json;
@@ -63,6 +60,18 @@ public class WxMenuGsonAdapter implements JsonSerializer<WxMenu>, JsonDeserializ
return buttonJson;
}
protected JsonObject convertToJson(WxMenu.WxMenuRule menuRule){
JsonObject matchRule = new JsonObject();
matchRule.addProperty("group_id",menuRule.getGroupId());
matchRule.addProperty("sex",menuRule.getSex());
matchRule.addProperty("country",menuRule.getCountry());
matchRule.addProperty("province",menuRule.getProvince());
matchRule.addProperty("city",menuRule.getCity());
matchRule.addProperty("client_platform_type",menuRule.getClientPlatformType());
matchRule.addProperty("language",menuRule.getLanguage());
return matchRule;
}
public WxMenu deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
/*
* 操蛋的微信