修复用户标签id类型不一致的问题 #175

This commit is contained in:
Binary Wang
2017-04-10 11:14:20 +08:00
parent 89470660ef
commit 0ff63ba3cb
3 changed files with 20 additions and 6 deletions

View File

@@ -9,13 +9,13 @@
package me.chanjar.weixin.common.util.json; package me.chanjar.weixin.common.util.json;
import java.util.List;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import java.util.List;
public class GsonHelper { public class GsonHelper {
@@ -130,6 +130,20 @@ public class GsonHelper {
return result.toArray(new Integer[0]); return result.toArray(new Integer[0]);
} }
public static Long[] getLongArray(JsonObject o, String string) {
JsonArray jsonArray = getAsJsonArray(o.getAsJsonArray(string));
if (jsonArray == null) {
return null;
}
List<Long> result = Lists.newArrayList();
for (int i = 0; i < jsonArray.size(); i++) {
result.add(jsonArray.get(i).getAsLong());
}
return result.toArray(new Long[0]);
}
public static JsonArray getAsJsonArray(JsonElement element) { public static JsonArray getAsJsonArray(JsonElement element) {
return element == null ? null : element.getAsJsonArray(); return element == null ? null : element.getAsJsonArray();
} }

View File

@@ -32,7 +32,7 @@ public class WxMpUser implements Serializable {
private Integer sexId; private Integer sexId;
private String remark; private String remark;
private Integer groupId; private Integer groupId;
private Integer[] tagIds; private Long[] tagIds;
public Boolean getSubscribe() { public Boolean getSubscribe() {
return this.subscribe; return this.subscribe;
@@ -150,11 +150,11 @@ public class WxMpUser implements Serializable {
this.groupId = groupId; this.groupId = groupId;
} }
public Integer[] getTagIds() { public Long[] getTagIds() {
return this.tagIds; return this.tagIds;
} }
public void setTagIds(Integer[] tagIds) { public void setTagIds(Long[] tagIds) {
this.tagIds = tagIds; this.tagIds = tagIds;
} }

View File

@@ -36,7 +36,7 @@ public class WxMpUserGsonAdapter implements JsonDeserializer<WxMpUser> {
Integer sexId = GsonHelper.getInteger(o, "sex"); Integer sexId = GsonHelper.getInteger(o, "sex");
wxMpUser.setRemark(GsonHelper.getString(o, "remark")); wxMpUser.setRemark(GsonHelper.getString(o, "remark"));
wxMpUser.setGroupId(GsonHelper.getInteger(o, "groupid")); wxMpUser.setGroupId(GsonHelper.getInteger(o, "groupid"));
wxMpUser.setTagIds(GsonHelper.getIntArray(o, "tagid_list")); wxMpUser.setTagIds(GsonHelper.getLongArray(o, "tagid_list"));
wxMpUser.setSexId(sexId); wxMpUser.setSexId(sexId);
if (new Integer(1).equals(sexId)) { if (new Integer(1).equals(sexId)) {
wxMpUser.setSex(""); wxMpUser.setSex("");