Class GsonPrimitiveConverter
java.lang.Object
eu.cloudnetservice.driver.impl.document.gson.send.GsonPrimitiveConverter
A class to simple convert between gson primitive types, java primitives or primitive elements.
- Since:
- 4.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull eu.cloudnetservice.driver.document.send.element.PrimitiveElementunwrapJsonPrimitive(@NonNull String key, @NonNull com.google.gson.JsonPrimitive primitive) Converts the given gson json primitive into a primitive element.static @NonNull com.google.gson.JsonPrimitivewrapAsPrimitive(@NonNull Object value) Wraps the given primitive type into a gson json primitive instance.
-
Constructor Details
-
GsonPrimitiveConverter
private GsonPrimitiveConverter()
-
-
Method Details
-
wrapAsPrimitive
@NonNull public static @NonNull com.google.gson.JsonPrimitive wrapAsPrimitive(@NonNull @NonNull Object value) Wraps the given primitive type into a gson json primitive instance.- Parameters:
value- the java primitive type to wrap into a gson value.- Returns:
- the gson json primitive instance wrapping the given value.
- Throws:
NullPointerException- if the given value is null.IllegalArgumentException- if the given value type is not a json primitive.
-
unwrapJsonPrimitive
@NonNull public static @NonNull eu.cloudnetservice.driver.document.send.element.PrimitiveElement unwrapJsonPrimitive(@NonNull @NonNull String key, @NonNull @NonNull com.google.gson.JsonPrimitive primitive) Converts the given gson json primitive into a primitive element.- Parameters:
key- the key to use for the primitive element.primitive- the gson json primitive value to unwrap and re-pack into a primitive element.- Returns:
- a primitive element constructed from the given key and gson json primitive.
- Throws:
NullPointerException- if the given key or gson json primitive is null.IllegalArgumentException- if the given gson json primitive contains an unknown json primitive type.
-