🎨 解析响应的Gson构建类调整为单例

This commit is contained in:
DDERGOU
2022-01-11 12:44:50 +08:00
committed by GitHub
parent 4c781ee7ee
commit ee17a5ee6f
5 changed files with 183 additions and 139 deletions

View File

@ -7,6 +7,7 @@ import me.chanjar.weixin.open.bean.WxOpenComponentAccessToken;
import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizationInfo;
import me.chanjar.weixin.open.bean.auth.WxOpenAuthorizerInfo;
import me.chanjar.weixin.open.bean.result.*;
import java.util.Objects;
/**
* @author <a href="https://github.com/007gzs">007</a>
@ -14,6 +15,7 @@ import me.chanjar.weixin.open.bean.result.*;
public class WxOpenGsonBuilder {
private static final GsonBuilder INSTANCE = new GsonBuilder();
private static volatile Gson GSON_INSTANCE;
static {
INSTANCE.disableHtmlEscaping();
@ -26,11 +28,17 @@ public class WxOpenGsonBuilder {
INSTANCE.registerTypeAdapter(WxOpenAuthorizerOptionResult.class, new WxOpenAuthorizerOptionResultGsonAdapter());
INSTANCE.registerTypeAdapter(WxFastMaAccountBasicInfoResult.class, new WxFastMaAccountBasicInfoGsonAdapter());
INSTANCE.registerTypeAdapter(WxOpenAuthorizerListResult.class, new WxOpenAuthorizerListResultGsonAdapter());
}
public static Gson create() {
return INSTANCE.create();
if (Objects.isNull(GSON_INSTANCE)) {
synchronized (GSON_INSTANCE) {
if (Objects.isNull(GSON_INSTANCE)) {
GSON_INSTANCE = INSTANCE.create();
}
}
}
return GSON_INSTANCE;
}
}