1
0
mirror of synced 2026-02-19 20:31:34 +08:00

🎨 解析响应的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

@@ -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;
}
}