Package growthbook.sdk.java.util
Class GrowthBookJsonUtils
java.lang.Object
growthbook.sdk.java.util.GrowthBookJsonUtils
INTERNAL: This convenience class was created to help with the serialization and deserialization of custom types.
Some types in the JSON source are tuples. This helps with transforming to and from POJOs.
The provided methods use a custom Gson instance that has all required type adapters registered.
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal com.google.gson.Gson
The Gson instance is exposed for convenience. -
Method Summary
Modifier and TypeMethodDescriptionstatic DataType
getElementType
(com.google.gson.JsonElement element) A convenience method to help work with types of JSON elementsstatic GrowthBookJsonUtils
The JSON utils singletonstatic com.google.gson.JsonElement
getJsonElementForObject
(Object object) Given a provided object, which can be a primitive or a serializable class, Will return a JSON element.static Object
Unwrap an object.
-
Field Details
-
gson
public final com.google.gson.Gson gsonThe Gson instance is exposed for convenience.
-
-
Method Details
-
getInstance
The JSON utils singleton- Returns:
- an instance of
GrowthBookJsonUtils
-
unwrap
Unwrap an object. If it's not a JsonElement, you'll get the object right back- Parameters:
o
- the JSON element to unwrap.- Returns:
- unwrapped or original object
-
getElementType
A convenience method to help work with types of JSON elements- Parameters:
element
- unknown JsonElement- Returns:
DataType
-
getJsonElementForObject
Given a provided object, which can be a primitive or a serializable class, Will return a JSON element. It will first attempt to detect it as a primitive type. If that doesn't work, it will try to serialize it. If serialization fails, null will be returned.- Parameters:
object
- Unknown typed object- Returns:
- the JSON element that gets created or null if serialization fails
-