🎨 #1619 企业微信获取用户信息接口优化,处理type为null情况下可能会导致的空指针问题
This commit is contained in:
@@ -89,7 +89,7 @@ public class WxCpUser implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 属性类型: 0-文本 1-网页
|
* 属性类型: 0-文本 1-网页
|
||||||
*/
|
*/
|
||||||
private int type;
|
private Integer type;
|
||||||
private String name;
|
private String name;
|
||||||
private String textValue;
|
private String textValue;
|
||||||
private String webUrl;
|
private String webUrl;
|
||||||
@@ -104,7 +104,7 @@ public class WxCpUser implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 属性类型: 0-本文 1-网页 2-小程序.
|
* 属性类型: 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"));
|
.setName(GsonHelper.getString(attrJsonElement.getAsJsonObject(), "name"));
|
||||||
user.getExtAttrs().add(attr);
|
user.getExtAttrs().add(attr);
|
||||||
|
|
||||||
|
if (type == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 0: {
|
case 0: {
|
||||||
attr.setTextValue(GsonHelper.getString(attrJsonElement.getAsJsonObject().get("text").getAsJsonObject(), "value"));
|
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 Integer type = GsonHelper.getInteger(element.getAsJsonObject(), "type");
|
||||||
final String name = GsonHelper.getString(element.getAsJsonObject(), "name");
|
final String name = GsonHelper.getString(element.getAsJsonObject(), "name");
|
||||||
|
|
||||||
|
if (type == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 0: {
|
case 0: {
|
||||||
user.getExternalAttrs()
|
user.getExternalAttrs()
|
||||||
@@ -253,6 +261,12 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
|
|||||||
for (WxCpUser.Attr attr : user.getExtAttrs()) {
|
for (WxCpUser.Attr attr : user.getExtAttrs()) {
|
||||||
JsonObject attrJson = new JsonObject();
|
JsonObject attrJson = new JsonObject();
|
||||||
|
|
||||||
|
attrsJsonArray.add(attrJson);
|
||||||
|
|
||||||
|
if (attr.getType() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
switch (attr.getType()) {
|
switch (attr.getType()) {
|
||||||
case 0: {
|
case 0: {
|
||||||
JsonObject text = new JsonObject();
|
JsonObject text = new JsonObject();
|
||||||
@@ -269,7 +283,6 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
|
|||||||
}
|
}
|
||||||
default: //ignored
|
default: //ignored
|
||||||
}
|
}
|
||||||
attrsJsonArray.add(attrJson);
|
|
||||||
}
|
}
|
||||||
JsonObject attrsJson = new JsonObject();
|
JsonObject attrsJson = new JsonObject();
|
||||||
attrsJson.add("attrs", attrsJsonArray);
|
attrsJson.add("attrs", attrsJsonArray);
|
||||||
@@ -293,6 +306,13 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
|
|||||||
JsonObject attrJson = new JsonObject();
|
JsonObject attrJson = new JsonObject();
|
||||||
attrJson.addProperty("type", attr.getType());
|
attrJson.addProperty("type", attr.getType());
|
||||||
attrJson.addProperty("name", attr.getName());
|
attrJson.addProperty("name", attr.getName());
|
||||||
|
|
||||||
|
attrsJsonArray.add(attrJson);
|
||||||
|
|
||||||
|
if (attr.getType() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
switch (attr.getType()) {
|
switch (attr.getType()) {
|
||||||
case 0: {
|
case 0: {
|
||||||
JsonObject text = new JsonObject();
|
JsonObject text = new JsonObject();
|
||||||
@@ -317,7 +337,6 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
|
|||||||
}
|
}
|
||||||
default://忽略
|
default://忽略
|
||||||
}
|
}
|
||||||
attrsJsonArray.add(attrJson);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
attrsJson.add(EXTERNAL_ATTR, attrsJsonArray);
|
attrsJson.add(EXTERNAL_ATTR, attrsJsonArray);
|
||||||
|
|||||||
Reference in New Issue
Block a user