mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-29 01:18:36 +08:00
🎨 解析响应的Gson构建类调整为单例
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user