🎨 #1659 Json解析统一优化

* 解决动态添加第一个公众号时由于configStorageMap为null报空指针异常

* Json解析统一优化

Co-authored-by: niefy <niefy@qq.com>
This commit is contained in:
niefy
2020-07-06 17:01:37 +08:00
committed by GitHub
parent 8121a521d3
commit 0adca9650d
114 changed files with 229 additions and 337 deletions

View File

@@ -2,7 +2,6 @@ package me.chanjar.weixin.open.api.impl;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -10,6 +9,7 @@ import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.crypto.SHA1;
import me.chanjar.weixin.common.util.http.URIUtil;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
@@ -33,7 +33,7 @@ import java.util.concurrent.locks.Lock;
@Slf4j
@AllArgsConstructor
public class WxOpenComponentServiceImpl implements WxOpenComponentService {
private static final JsonParser JSON_PARSER = new JsonParser();
private static final Map<String, WxOpenMaService> WX_OPEN_MA_SERVICE_MAP = new ConcurrentHashMap<>();
private static final Map<String, WxMpService> WX_OPEN_MP_SERVICE_MAP = new ConcurrentHashMap<>();
private static final Map<String, WxOpenFastMaService> WX_OPEN_FAST_MA_SERVICE_MAP = new ConcurrentHashMap<>();
@@ -435,7 +435,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
@Override
public List<WxOpenMaCodeTemplate> getTemplateDraftList() throws WxErrorException {
String responseContent = get(GET_TEMPLATE_DRAFT_LIST_URL, "access_token");
JsonObject response = JSON_PARSER.parse(StringUtils.defaultString(responseContent, "{}")).getAsJsonObject();
JsonObject response = GsonParser.parse(StringUtils.defaultString(responseContent, "{}"));
boolean hasDraftList = response.has("draft_list");
if (hasDraftList) {
return WxOpenGsonBuilder.create().fromJson(response.getAsJsonArray("draft_list"),
@@ -449,7 +449,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
@Override
public List<WxOpenMaCodeTemplate> getTemplateList() throws WxErrorException {
String responseContent = get(GET_TEMPLATE_LIST_URL, "access_token");
JsonObject response = JSON_PARSER.parse(StringUtils.defaultString(responseContent, "{}")).getAsJsonObject();
JsonObject response = GsonParser.parse(StringUtils.defaultString(responseContent, "{}"));
boolean hasTemplateList = response.has("template_list");
if (hasTemplateList) {
return WxOpenGsonBuilder.create().fromJson(response.getAsJsonArray("template_list"),