瀏覽代碼

#136 修复WxMenuRule反序列化的问题tag_id为空的问题

master
Binary Wang 7 年之前
父節點
當前提交
3875635a8a
共有 3 個檔案被更改,包括 17 行新增2 行删除
  1. +5
    -0
      weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuRule.java
  2. +1
    -0
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java
  3. +11
    -2
      weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java

+ 5
- 0
weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/menu/WxMenuRule.java 查看文件

@@ -1,5 +1,6 @@
package me.chanjar.weixin.common.bean.menu;

import com.google.gson.annotations.SerializedName;
import me.chanjar.weixin.common.util.ToStringUtils;

import java.io.Serializable;
@@ -7,6 +8,10 @@ import java.io.Serializable;
public class WxMenuRule implements Serializable {
private static final long serialVersionUID = -4587181819499286670L;

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


+ 1
- 0
weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java 查看文件

@@ -70,6 +70,7 @@ public class WxMenuGsonAdapter implements JsonSerializer<WxMenu>, JsonDeserializ
return matchRule;
}

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


+ 11
- 2
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java 查看文件

@@ -9,9 +9,10 @@ import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.test.ApiTestModule;
import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult;
import me.chanjar.weixin.mp.bean.menu.WxMpMenu;
import org.testng.*;
import org.testng.annotations.*;

import static org.testng.Assert.*;

/**
* 测试菜单
*
@@ -87,6 +88,14 @@ public class WxMpMenuServiceImplTest {
System.out.println(this.menuId);
}

@Test(dependsOnMethods = {"testCreateConditionalMenu"})
public void testMenuGet_AfterCreateConditionalMenu() throws WxErrorException {
WxMpMenu wxMenu = this.wxService.getMenuService().menuGet();
assertNotNull(wxMenu);
System.out.println(wxMenu.toJson());
assertNotNull(wxMenu.getConditionalMenu().get(0).getRule().getTagId());
}

@Test(dependsOnMethods = {"testCreateConditionalMenu"})
public void testDeleteConditionalMenu() throws WxErrorException {
this.wxService.getMenuService().menuDelete(menuId);
@@ -134,7 +143,7 @@ public class WxMpMenuServiceImplTest {
@Test(dependsOnMethods = {"testMenuCreate"})
public void testMenuGet() throws WxErrorException {
WxMpMenu wxMenu = this.wxService.getMenuService().menuGet();
Assert.assertNotNull(wxMenu);
assertNotNull(wxMenu);
System.out.println(wxMenu.toJson());
}



Loading…
取消
儲存