【企业微信】weixin-java-cp 字段更新 WxCpDepart.java by 0katekate0 · Pull Request #2452 · binarywang/WxJava · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,12 @@
*/
package me.chanjar.weixin.cp.util.json;

import java.lang.reflect.Type;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.*;
import me.chanjar.weixin.common.util.json.GsonHelper;
import me.chanjar.weixin.cp.bean.WxCpDepart;

import java.lang.reflect.Type;

/**
* WxCpDepart的gson适配器.
*
Expand All @@ -29,6 +23,7 @@ public class WxCpDepartGsonAdapter implements JsonSerializer<WxCpDepart>, JsonDe
private static final String ID = "id";
private static final String NAME = "name";
private static final String EN_NAME = "name_en";
private static final String DEPARTMENT_LEADER = "department_leader";
private static final String PARENT_ID = "parentid";
private static final String ORDER = "order";

Expand All @@ -44,6 +39,13 @@ public JsonElement serialize(WxCpDepart group, Type typeOfSrc, JsonSerialization
if (group.getEnName() != null) {
json.addProperty(EN_NAME, group.getEnName());
}
if (group.getDepartmentLeader() != null) {
JsonArray jsonArray = new JsonArray();
for (String department : group.getDepartmentLeader()) {
jsonArray.add(new JsonPrimitive(department));
}
json.add(DEPARTMENT_LEADER, jsonArray);
}
if (group.getParentId() != null) {
json.addProperty(PARENT_ID, group.getParentId());
}
Expand All @@ -67,6 +69,15 @@ public WxCpDepart deserialize(JsonElement json, Type typeOfT, JsonDeserializatio
if (departJson.get(EN_NAME) != null && !departJson.get(EN_NAME).isJsonNull()) {
depart.setEnName(GsonHelper.getAsString(departJson.get(EN_NAME)));
}
if (departJson.getAsJsonArray(DEPARTMENT_LEADER) != null && !departJson.get(DEPARTMENT_LEADER).isJsonNull()) {
JsonArray jsonArray = departJson.getAsJsonArray(DEPARTMENT_LEADER);
String[] departments = new String[jsonArray.size()];
int i = 0;
for (JsonElement jsonElement : jsonArray) {
departments[i++] = jsonElement.getAsString();
}
depart.setDepartmentLeader(departments);
}
if (departJson.get(ORDER) != null && !departJson.get(ORDER).isJsonNull()) {
depart.setOrder(GsonHelper.getAsLong(departJson.get(ORDER)));
}
Expand Down