Package dev.demeng.pluginbase.gson
Class GsonProvider
java.lang.Object
dev.demeng.pluginbase.gson.GsonProvider
Provides static instances of
Gson.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull com.google.gson.JsonParserparser()Returns the sharedJsonParserinstance.static @NotNull com.google.gson.GsonReturns aGsoninstance configured with pretty printing, null serialization, and HTML escaping disabled.static @NotNull com.google.gson.JsonObjectreadObject(@NotNull Reader reader) Parses the content of the givenReaderinto aJsonObject.static @NotNull com.google.gson.JsonObjectreadObject(@NotNull String s) Parses a JSON string into aJsonObject.static @NotNull com.google.gson.Gsonstandard()Returns the standardGsoninstance configured with null serialization and HTML escaping disabled.static @NotNull StringtoString(@NotNull com.google.gson.JsonElement element) Serializes aJsonElementto a string using standard formatting.static @NotNull StringtoStringPretty(@NotNull com.google.gson.JsonElement element) Serializes aJsonElementto a pretty-printed string.static voidwriteElement(@NotNull Appendable writer, @NotNull com.google.gson.JsonElement element) Serializes aJsonElementto the givenAppendableusing standard formatting.static voidwriteElementPretty(@NotNull Appendable writer, @NotNull com.google.gson.JsonElement element) Serializes aJsonElementto the givenAppendableusing pretty-print formatting.static voidwriteObject(@NotNull Appendable writer, @NotNull com.google.gson.JsonObject object) Serializes aJsonObjectto the givenAppendableusing standard formatting.static voidwriteObjectPretty(@NotNull Appendable writer, @NotNull com.google.gson.JsonObject object) Serializes aJsonObjectto the givenAppendableusing pretty-print formatting.
-
Constructor Details
-
GsonProvider
public GsonProvider()
-
-
Method Details
-
standard
@NotNull public static @NotNull com.google.gson.Gson standard()Returns the standardGsoninstance configured with null serialization and HTML escaping disabled.- Returns:
- the standard Gson instance
-
prettyPrinting
@NotNull public static @NotNull com.google.gson.Gson prettyPrinting()Returns aGsoninstance configured with pretty printing, null serialization, and HTML escaping disabled.- Returns:
- the pretty-printing Gson instance
-
parser
@NotNull public static @NotNull com.google.gson.JsonParser parser()Returns the sharedJsonParserinstance.- Returns:
- the shared JsonParser
-
readObject
@NotNull public static @NotNull com.google.gson.JsonObject readObject(@NotNull @NotNull Reader reader) Parses the content of the givenReaderinto aJsonObject.- Parameters:
reader- the reader supplying the JSON content- Returns:
- the parsed JsonObject
-
readObject
Parses a JSON string into aJsonObject.- Parameters:
s- the JSON string to parse- Returns:
- the parsed JsonObject
-
writeObject
public static void writeObject(@NotNull @NotNull Appendable writer, @NotNull @NotNull com.google.gson.JsonObject object) Serializes aJsonObjectto the givenAppendableusing standard formatting.- Parameters:
writer- the target to write the JSON toobject- the object to serialize
-
writeObjectPretty
public static void writeObjectPretty(@NotNull @NotNull Appendable writer, @NotNull @NotNull com.google.gson.JsonObject object) Serializes aJsonObjectto the givenAppendableusing pretty-print formatting.- Parameters:
writer- the target to write the JSON toobject- the object to serialize
-
writeElement
public static void writeElement(@NotNull @NotNull Appendable writer, @NotNull @NotNull com.google.gson.JsonElement element) Serializes aJsonElementto the givenAppendableusing standard formatting.- Parameters:
writer- the target to write the JSON toelement- the element to serialize
-
writeElementPretty
public static void writeElementPretty(@NotNull @NotNull Appendable writer, @NotNull @NotNull com.google.gson.JsonElement element) Serializes aJsonElementto the givenAppendableusing pretty-print formatting.- Parameters:
writer- the target to write the JSON toelement- the element to serialize
-
toString
@NotNull public static @NotNull String toString(@NotNull @NotNull com.google.gson.JsonElement element) Serializes aJsonElementto a string using standard formatting.- Parameters:
element- the element to serialize- Returns:
- the JSON string representation
-
toStringPretty
@NotNull public static @NotNull String toStringPretty(@NotNull @NotNull com.google.gson.JsonElement element) Serializes aJsonElementto a pretty-printed string.- Parameters:
element- the element to serialize- Returns:
- the pretty-printed JSON string representation
-