mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-05 17:38:05 +08:00
🎨 #1619 企业微信获取用户信息接口优化,处理type为null情况下可能会导致的空指针问题
This commit is contained in:
parent
3b37f52235
commit
8256c46db2
@ -89,7 +89,7 @@ public class WxCpUser implements Serializable {
|
||||
/**
|
||||
* 属性类型: 0-文本 1-网页
|
||||
*/
|
||||
private int type;
|
||||
private Integer type;
|
||||
private String name;
|
||||
private String textValue;
|
||||
private String webUrl;
|
||||
@ -104,7 +104,7 @@ public class WxCpUser implements Serializable {
|
||||
/**
|
||||
* 属性类型: 0-本文 1-网页 2-小程序.
|
||||
*/
|
||||
private int type;
|
||||
private Integer type;
|
||||
/**
|
||||
* 属性名称: 需要先确保在管理端有创建改属性,否则会忽略.
|
||||
*/
|
||||
|
@ -98,6 +98,10 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
|
||||
.setName(GsonHelper.getString(attrJsonElement.getAsJsonObject(), "name"));
|
||||
user.getExtAttrs().add(attr);
|
||||
|
||||
if (type == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case 0: {
|
||||
attr.setTextValue(GsonHelper.getString(attrJsonElement.getAsJsonObject().get("text").getAsJsonObject(), "value"));
|
||||
@ -120,6 +124,10 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
|
||||
final Integer type = GsonHelper.getInteger(element.getAsJsonObject(), "type");
|
||||
final String name = GsonHelper.getString(element.getAsJsonObject(), "name");
|
||||
|
||||
if (type == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case 0: {
|
||||
user.getExternalAttrs()
|
||||
@ -253,6 +261,12 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
|
||||
for (WxCpUser.Attr attr : user.getExtAttrs()) {
|
||||
JsonObject attrJson = new JsonObject();
|
||||
|
||||
attrsJsonArray.add(attrJson);
|
||||
|
||||
if (attr.getType() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (attr.getType()) {
|
||||
case 0: {
|
||||
JsonObject text = new JsonObject();
|
||||
@ -269,7 +283,6 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
|
||||
}
|
||||
default: //ignored
|
||||
}
|
||||
attrsJsonArray.add(attrJson);
|
||||
}
|
||||
JsonObject attrsJson = new JsonObject();
|
||||
attrsJson.add("attrs", attrsJsonArray);
|
||||
@ -293,6 +306,13 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
|
||||
JsonObject attrJson = new JsonObject();
|
||||
attrJson.addProperty("type", attr.getType());
|
||||
attrJson.addProperty("name", attr.getName());
|
||||
|
||||
attrsJsonArray.add(attrJson);
|
||||
|
||||
if (attr.getType() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (attr.getType()) {
|
||||
case 0: {
|
||||
JsonObject text = new JsonObject();
|
||||
@ -317,7 +337,6 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
|
||||
}
|
||||
default://忽略
|
||||
}
|
||||
attrsJsonArray.add(attrJson);
|
||||
}
|
||||
|
||||
attrsJson.add(EXTERNAL_ATTR, attrsJsonArray);
|
||||
|
Loading…
Reference in New Issue
Block a user