88 */
99package me .chanjar .weixin .common .util .json ;
1010
11- import java .lang .reflect .Type ;
12-
13- import com .google .gson .Gson ;
1411import com .google .gson .JsonArray ;
1512import com .google .gson .JsonDeserializationContext ;
1613import com .google .gson .JsonDeserializer ;
1916import com .google .gson .JsonParseException ;
2017import com .google .gson .JsonSerializationContext ;
2118import com .google .gson .JsonSerializer ;
22-
2319import me .chanjar .weixin .common .bean .WxMenu ;
2420
21+ import java .lang .reflect .Type ;
22+
2523/**
2624 *
2725 * @author Daniel Qian
@@ -40,8 +38,7 @@ public JsonElement serialize(WxMenu menu, Type typeOfSrc, JsonSerializationConte
4038 json .add ("button" , buttonArray );
4139
4240 if (menu .getMatchRule () != null ) {
43- Gson gson = new Gson ();
44- json .add ("matchrule" , gson .toJsonTree (menu .getMatchRule ()));
41+ json .add ("matchrule" , convertToJson (menu .getMatchRule ()));
4542 }
4643
4744 return json ;
@@ -63,6 +60,18 @@ protected JsonObject convertToJson(WxMenu.WxMenuButton button) {
6360 return buttonJson ;
6461 }
6562
63+ protected JsonObject convertToJson (WxMenu .WxMenuRule menuRule ){
64+ JsonObject matchRule = new JsonObject ();
65+ matchRule .addProperty ("group_id" ,menuRule .getGroupId ());
66+ matchRule .addProperty ("sex" ,menuRule .getSex ());
67+ matchRule .addProperty ("country" ,menuRule .getCountry ());
68+ matchRule .addProperty ("province" ,menuRule .getProvince ());
69+ matchRule .addProperty ("city" ,menuRule .getCity ());
70+ matchRule .addProperty ("client_platform_type" ,menuRule .getClientPlatformType ());
71+ matchRule .addProperty ("language" ,menuRule .getLanguage ());
72+ return matchRule ;
73+ }
74+
6675 public WxMenu deserialize (JsonElement json , Type typeOfT , JsonDeserializationContext context ) throws JsonParseException {
6776 /*
6877 * 操蛋的微信
0 commit comments