feat:完善游戏房状态维护

This commit is contained in:
max
2024-05-30 19:18:05 +08:00
parent 2396eb9089
commit 5be8ebde3a
51 changed files with 7346 additions and 426 deletions

View File

@@ -7,16 +7,37 @@ import com.google.gson.Gson;
*/
public class JsonUtils {
public static Gson gson;
private static Gson gson;
public static String toJson(Object object) {
public static Gson getGson() {
if (gson == null) {
gson = new Gson();
}
return gson;
}
/**
* 解析json
*
* @return 如果解析出错,则返回空对象
*/
public static <T> T fromJson(final String json, final Class<T> type) {
try {
if (json == null || type == null) {
return null;
}
return getGson().fromJson(json, type);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static String toJson(Object object) {
String result = null;
try {
if (object != null) {
result = gson.toJson(object);
result = getGson().toJson(object);
}
} catch (Exception ex) {
ex.printStackTrace();