Skip to content

Commit 3875635

Browse files
committed
binarywang#136 修复WxMenuRule反序列化的问题tag_id为空的问题
1 parent 7c3f6cc commit 3875635

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

‎weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuRule.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package me.chanjar.weixin.common.bean.menu;
22

3+
import com.google.gson.annotations.SerializedName;
34
import me.chanjar.weixin.common.util.ToStringUtils;
45

56
import java.io.Serializable;
67

78
public class WxMenuRule implements Serializable {
89
private static final long serialVersionUID = -4587181819499286670L;
910

11+
/**
12+
* 变态的微信接口,反序列化时这里反人类的使用和序列化时不一样的名字
13+
*/
14+
@SerializedName(value = "tag_id", alternate = "group_id")
1015
private String tagId;
1116
private String sex;
1217
private String country;

‎weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ protected JsonObject convertToJson(WxMenuRule menuRule) {
7070
return matchRule;
7171
}
7272

73+
@Deprecated
7374
private WxMenuRule convertToRule(JsonObject json) {
7475
WxMenuRule menuRule = new WxMenuRule();
7576
//变态的微信接口,这里居然反人类的使用和序列化时不一样的名字

‎weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
import me.chanjar.weixin.mp.api.test.ApiTestModule;
1010
import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult;
1111
import me.chanjar.weixin.mp.bean.menu.WxMpMenu;
12-
import org.testng.*;
1312
import org.testng.annotations.*;
1413

14+
import static org.testng.Assert.*;
15+
1516
/**
1617
* 测试菜单
1718
*
@@ -87,6 +88,14 @@ public void testCreateConditionalMenu() throws WxErrorException {
8788
System.out.println(this.menuId);
8889
}
8990

91+
@Test(dependsOnMethods = {"testCreateConditionalMenu"})
92+
public void testMenuGet_AfterCreateConditionalMenu() throws WxErrorException {
93+
WxMpMenu wxMenu = this.wxService.getMenuService().menuGet();
94+
assertNotNull(wxMenu);
95+
System.out.println(wxMenu.toJson());
96+
assertNotNull(wxMenu.getConditionalMenu().get(0).getRule().getTagId());
97+
}
98+
9099
@Test(dependsOnMethods = {"testCreateConditionalMenu"})
91100
public void testDeleteConditionalMenu() throws WxErrorException {
92101
this.wxService.getMenuService().menuDelete(menuId);
@@ -134,7 +143,7 @@ public void testCreateMenu_by_json() throws WxErrorException {
134143
@Test(dependsOnMethods = {"testMenuCreate"})
135144
public void testMenuGet() throws WxErrorException {
136145
WxMpMenu wxMenu = this.wxService.getMenuService().menuGet();
137-
Assert.assertNotNull(wxMenu);
146+
assertNotNull(wxMenu);
138147
System.out.println(wxMenu.toJson());
139148
}
140149

0 commit comments

Comments
 (0)