mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-05-08 22:57:47 +08:00
🎨 解析响应的Gson构建类调整为单例
This commit is contained in:
parent
4c781ee7ee
commit
ee17a5ee6f
@ -7,6 +7,7 @@ import me.chanjar.weixin.common.bean.WxNetCheckResult;
|
||||
import me.chanjar.weixin.common.bean.menu.WxMenu;
|
||||
import me.chanjar.weixin.common.error.WxError;
|
||||
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* .
|
||||
@ -14,6 +15,7 @@ import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
|
||||
*/
|
||||
public class WxGsonBuilder {
|
||||
private static final GsonBuilder INSTANCE = new GsonBuilder();
|
||||
private static volatile Gson GSON_INSTANCE;
|
||||
|
||||
static {
|
||||
INSTANCE.disableHtmlEscaping();
|
||||
@ -26,7 +28,14 @@ public class WxGsonBuilder {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import me.chanjar.weixin.cp.bean.WxCpChat;
|
||||
import me.chanjar.weixin.cp.bean.WxCpDepart;
|
||||
import me.chanjar.weixin.cp.bean.WxCpTag;
|
||||
import me.chanjar.weixin.cp.bean.WxCpUser;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author Daniel Qian
|
||||
@ -16,6 +17,7 @@ import me.chanjar.weixin.cp.bean.WxCpUser;
|
||||
public class WxCpGsonBuilder {
|
||||
|
||||
private static final GsonBuilder INSTANCE = new GsonBuilder();
|
||||
private static volatile Gson GSON_INSTANCE;
|
||||
|
||||
static {
|
||||
INSTANCE.disableHtmlEscaping();
|
||||
@ -28,7 +30,14 @@ public class WxCpGsonBuilder {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,12 +11,14 @@ import cn.binarywang.wx.miniapp.bean.code.WxMaCodeVersionDistribution;
|
||||
import cn.binarywang.wx.miniapp.json.adaptor.*;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public class WxMaGsonBuilder {
|
||||
private static final GsonBuilder INSTANCE = new GsonBuilder();
|
||||
private static volatile Gson GSON_INSTANCE;
|
||||
|
||||
static {
|
||||
INSTANCE.disableHtmlEscaping();
|
||||
@ -31,7 +33,14 @@ public class WxMaGsonBuilder {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import me.chanjar.weixin.mp.bean.result.*;
|
||||
import me.chanjar.weixin.mp.bean.subscribe.WxMpSubscribeMessage;
|
||||
import me.chanjar.weixin.mp.bean.template.WxMpTemplateIndustry;
|
||||
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author someone
|
||||
@ -23,6 +24,7 @@ import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
|
||||
public class WxMpGsonBuilder {
|
||||
|
||||
private static final GsonBuilder INSTANCE = new GsonBuilder();
|
||||
private static volatile Gson GSON_INSTANCE;
|
||||
|
||||
static {
|
||||
INSTANCE.disableHtmlEscaping();
|
||||
@ -64,7 +66,14 @@ public class WxMpGsonBuilder {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user