Package dev.demeng.pluginbase.gson
Class JsonBuilder
java.lang.Object
dev.demeng.pluginbase.gson.JsonBuilder
Builder utilities for creating GSON Objects/Arrays.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAJsonArraybuilder utilitystatic interfaceAJsonObjectbuilder utility -
Method Summary
Modifier and TypeMethodDescriptionstatic JsonBuilder.JsonArrayBuilderarray()Creates a new array builder, with no initial valuesstatic JsonBuilder.JsonArrayBuilderarray(com.google.gson.JsonArray array) Creates a new array builder, without copying the passed array.static JsonBuilder.JsonArrayBuilderarray(com.google.gson.JsonArray array, boolean copy) Creates a new array builderstatic Collector<com.google.gson.JsonElement,JsonBuilder.JsonArrayBuilder, com.google.gson.JsonArray> Returns a collector which forms a JsonArray from JsonElementsstatic <T> Collector<T,JsonBuilder.JsonArrayBuilder, com.google.gson.JsonArray> collectToArray(Function<? super T, com.google.gson.JsonElement> valueMapper) Returns a collector which forms a JsonArray using the value mapperstatic <T> Collector<T,JsonBuilder.JsonObjectBuilder, com.google.gson.JsonObject> collectToObject(Function<? super T, String> keyMapper, Function<? super T, com.google.gson.JsonElement> valueMapper) Returns a collector which forms a JsonObject using the key and value mappersstatic com.google.gson.JsonNullReturns an instance ofJsonNull.object()Creates a new object builder, with no initial valuesobject(com.google.gson.JsonObject object) Creates a new object builder, without copying the passed object.object(com.google.gson.JsonObject object, boolean copy) Creates a new object builderstatic com.google.gson.JsonElementCreates a JsonPrimitive from the given value.static com.google.gson.JsonElementCreates a JsonPrimitive from the given value.static com.google.gson.JsonElementCreates a JsonPrimitive from the given value.static com.google.gson.JsonElementCreates a JsonPrimitive from the given value.static com.google.gson.JsonPrimitiveprimitiveNonNull(Boolean value) Creates a JsonPrimitive from the given value.static com.google.gson.JsonPrimitiveprimitiveNonNull(Character value) Creates a JsonPrimitive from the given value.static com.google.gson.JsonPrimitiveprimitiveNonNull(Number value) Creates a JsonPrimitive from the given value.static com.google.gson.JsonPrimitiveprimitiveNonNull(String value) Creates a JsonPrimitive from the given value.
-
Method Details
-
object
Creates a new object builderIf copy is not true, the passed object will be mutated by the builder methods.
- Parameters:
object- the object to base the new builder uponcopy- if the object should be deep copied, or just referenced.- Returns:
- a new builder
-
object
Creates a new object builder, without copying the passed object.Equivalent to calling
object(JsonObject, boolean)with copy = false.- Parameters:
object- the object to base the new builder upon- Returns:
- a new builder
-
object
Creates a new object builder, with no initial values- Returns:
- a new builder
-
array
Creates a new array builderIf copy is not true, the passed array will be mutated by the builder methods.
- Parameters:
array- the array to base the new builder uponcopy- if the array should be deep copied, or just referenced.- Returns:
- a new builder
-
array
Creates a new array builder, without copying the passed array.Equivalent to calling
array(JsonArray, boolean)with copy = false.- Parameters:
array- the array to base the new builder upon- Returns:
- a new builder
-
array
Creates a new array builder, with no initial values- Returns:
- a new builder
-
primitive
Creates a JsonPrimitive from the given value.If the value is null,
nullValue()is returned.- Parameters:
value- the value- Returns:
- a json primitive for the value
-
primitive
Creates a JsonPrimitive from the given value.If the value is null,
nullValue()is returned.- Parameters:
value- the value- Returns:
- a json primitive for the value
-
primitive
Creates a JsonPrimitive from the given value.If the value is null,
nullValue()is returned.- Parameters:
value- the value- Returns:
- a json primitive for the value
-
primitive
Creates a JsonPrimitive from the given value.If the value is null,
nullValue()is returned.- Parameters:
value- the value- Returns:
- a json primitive for the value
-
nullValue
public static com.google.gson.JsonNull nullValue()Returns an instance ofJsonNull.- Returns:
- a json null instance
-
primitiveNonNull
Creates a JsonPrimitive from the given value.If the value is null, a
NullPointerExceptionwill be thrown.- Parameters:
value- the value- Returns:
- a json primitive for the value
- Throws:
NullPointerException- if value is null
-
primitiveNonNull
Creates a JsonPrimitive from the given value.If the value is null, a
NullPointerExceptionwill be thrown.- Parameters:
value- the value- Returns:
- a json primitive for the value
- Throws:
NullPointerException- if value is null
-
primitiveNonNull
Creates a JsonPrimitive from the given value.If the value is null, a
NullPointerExceptionwill be thrown.- Parameters:
value- the value- Returns:
- a json primitive for the value
- Throws:
NullPointerException- if value is null
-
primitiveNonNull
Creates a JsonPrimitive from the given value.If the value is null, a
NullPointerExceptionwill be thrown.- Parameters:
value- the value- Returns:
- a json primitive for the value
- Throws:
NullPointerException- if value is null
-
collectToObject
public static <T> Collector<T,JsonBuilder.JsonObjectBuilder, collectToObjectcom.google.gson.JsonObject> (Function<? super T, String> keyMapper, Function<? super T, com.google.gson.JsonElement> valueMapper) Returns a collector which forms a JsonObject using the key and value mappers- Type Parameters:
T- the type- Parameters:
keyMapper- the function to map from T toStringvalueMapper- the function to map from T toJsonElement- Returns:
- a new collector
-
collectToArray
public static <T> Collector<T,JsonBuilder.JsonArrayBuilder, collectToArraycom.google.gson.JsonArray> (Function<? super T, com.google.gson.JsonElement> valueMapper) Returns a collector which forms a JsonArray using the value mapper- Type Parameters:
T- the type- Parameters:
valueMapper- the function to map from T toJsonElement- Returns:
- a new collector
-
collectToArray
public static Collector<com.google.gson.JsonElement,JsonBuilder.JsonArrayBuilder, collectToArray()com.google.gson.JsonArray> Returns a collector which forms a JsonArray from JsonElements- Returns:
- a new collector
-