From 92c5d62af42484d345fcda4103bb6f3bce2a25fa Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sun, 17 Nov 2019 00:55:55 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20#1265=20=E4=BC=81=E4=B8=9A=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E9=80=9A=E8=AE=AF=E5=BD=95=E6=8E=A5=E5=8F=A3=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=AE=BE=E7=BD=AE=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java | 4 ++++ .../me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java | 4 ++++ .../weixin/cp/util/json/WxCpUserGsonAdapterTest.java | 6 +++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java index 8f4e4989cc..b7389afa2b 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java @@ -27,6 +27,10 @@ public class WxCpUser implements Serializable { private Gender gender; private String email; private String avatar; + /** + * 地址。长度最大128个字符 + */ + private String address; private String avatarMediaId; private Integer status; private Integer enable; diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java index ed125c5708..482a42b47b 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java @@ -66,6 +66,7 @@ public WxCpUser deserialize(JsonElement json, Type typeOfT, JsonDeserializationC user.setGender(Gender.fromCode(GsonHelper.getString(o, "gender"))); user.setEmail(GsonHelper.getString(o, "email")); user.setAvatar(GsonHelper.getString(o, "avatar")); + user.setAddress(GsonHelper.getString(o, "address")); user.setAvatarMediaId(GsonHelper.getString(o, "avatar_mediaid")); user.setStatus(GsonHelper.getInteger(o, "status")); user.setEnable(GsonHelper.getInteger(o, "enable")); @@ -186,6 +187,9 @@ public JsonElement serialize(WxCpUser user, Type typeOfSrc, JsonSerializationCon if (user.getAvatar() != null) { o.addProperty("avatar", user.getAvatar()); } + if (user.getAddress() != null) { + o.addProperty("address", user.getAddress()); + } if (user.getAvatarMediaId() != null) { o.addProperty("avatar_mediaid", user.getAvatarMediaId()); } diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapterTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapterTest.java index 9cdc51f885..d17700220d 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapterTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapterTest.java @@ -1,8 +1,7 @@ package me.chanjar.weixin.cp.util.json; -import org.testng.annotations.*; - import me.chanjar.weixin.cp.bean.WxCpUser; +import org.testng.annotations.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -32,6 +31,7 @@ public void testDeserialize() { " \"isleader\": 1,\n" + " \"avatar\": \"http://wx.qlogo.cn/mmopen/ajNVdqHZLLA3WJ6DSZUfiakYe37PKnQhBIeOQBO4czqrnZDS79FH5Wm5m4X69TBicnHFlhiafvDwklOpZeXYQQ2icg/0\",\n" + " \"telephone\": \"020-123456\",\n" + + " \"address\": \"广州市海珠区新港中路\"," + " \"enable\": 1,\n" + " \"alias\": \"jackzhang\",\n" + " \"extattr\": {\n" + @@ -82,7 +82,7 @@ public void testDeserialize() { assertThat(user.getOrders()[0]).isEqualTo(1); assertThat(user.getOrders()[1]).isEqualTo(2); - + assertThat(user.getAddress()).isEqualTo("广州市海珠区新港中路"); assertThat(user.getExternalAttrs()).isNotEmpty(); final WxCpUser.ExternalAttribute externalAttr1 = user.getExternalAttrs().get(0);