RuneHive-Game
Loading...
Searching...
No Matches
GsonUtils.java
Go to the documentation of this file.
1package com.runehive.util;
2
3import com.google.gson.Gson;
4import com.google.gson.GsonBuilder;
5
6import java.util.OptionalInt;
7
8public enum GsonUtils {
9
10 ;
11
12 public static final ThreadLocal<Gson> JSON_ALLOW_NULL = ThreadLocal.withInitial(() ->
13 new GsonBuilder().disableHtmlEscaping().serializeNulls().create());
14 public static final ThreadLocal<Gson> JSON_PRETTY_ALLOW_NULL = ThreadLocal.withInitial(() ->
15 new GsonBuilder()
16 .registerTypeAdapter(OptionalInt.class, new OptionalIntAdapter())
17 .setPrettyPrinting()
18 .disableHtmlEscaping()
19 .serializeNulls()
20 .create());
21 public static final ThreadLocal<Gson> JSON_PRETTY_NO_NULLS = ThreadLocal.withInitial(() ->
22 new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create());
23
24 public static Gson jsonAllowNull() {
25 return JSON_ALLOW_NULL.get();
26 }
27
28 public static Gson jsonPrettyAllowNull() {
29 return JSON_PRETTY_ALLOW_NULL.get();
30 }
31
32 public static Gson jsonPrettyNoNulls() {
33 return JSON_PRETTY_NO_NULLS.get();
34 }
35
36 public static Gson json() {
37 return jsonPrettyAllowNull();
38 }
39
40}
static Gson jsonPrettyAllowNull()
static final ThreadLocal< Gson > JSON_PRETTY_NO_NULLS
static final ThreadLocal< Gson > JSON_PRETTY_ALLOW_NULL
static Gson jsonPrettyNoNulls()
static final ThreadLocal< Gson > JSON_ALLOW_NULL