RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
GsonUtils.java
1package com.osroyale.util;
2
3import com.google.gson.Gson;
4import com.google.gson.GsonBuilder;
5
6import java.util.OptionalInt;
7
24
25public enum GsonUtils {
26
27 ;
28
29 public static final ThreadLocal<Gson> JSON_ALLOW_NULL = ThreadLocal.withInitial(() ->
30 new GsonBuilder().disableHtmlEscaping().serializeNulls().create());
31 public static final ThreadLocal<Gson> JSON_PRETTY_ALLOW_NULL = ThreadLocal.withInitial(() ->
32 new GsonBuilder()
33 .registerTypeAdapter(OptionalInt.class, new OptionalIntAdapter())
34 .setPrettyPrinting()
35 .disableHtmlEscaping()
36 .serializeNulls()
37 .create());
38 public static final ThreadLocal<Gson> JSON_PRETTY_NO_NULLS = ThreadLocal.withInitial(() ->
39 new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create());
40
41 public static Gson jsonAllowNull() {
42 return JSON_ALLOW_NULL.get();
43 }
44
45 public static Gson jsonPrettyAllowNull() {
46 return JSON_PRETTY_ALLOW_NULL.get();
47 }
48
49 public static Gson jsonPrettyNoNulls() {
50 return JSON_PRETTY_NO_NULLS.get();
51 }
52
53 public static Gson json() {
54 return jsonPrettyAllowNull();
55 }
56
57}