public abstract class JsonSerialization
extends java.lang.Object
While the LaunchDarkly Java-based SDKs have used Gson
internally in the past, they may not always do so-- and even if they do, some SDK distributions may
embed their own copy of Gson with modified (shaded) class names so that it does not conflict with
any Gson instance elsewhere in the classpath. For both of those reasons, applications should not
assume that Gson.toGson()
and Gson.fromGson()
-- or any other JSON framework that is
based on reflection-- will work correctly for SDK classes, whose correct JSON representations do
not necessarily correspond to their internal field layout. Instead, they should always use one of
the following:
JsonSerialization
methods.
LDGson
.
LDValue
, you may also use the convenience methods LDValue.toJsonString()
and
LDValue.parse(String)
.
Modifier and Type | Method and Description |
---|---|
static <T extends JsonSerializable> |
deserialize(java.lang.String json,
java.lang.Class<T> objectClass)
Parses an object from its JSON representation.
|
static <T extends JsonSerializable> |
serialize(T instance)
Converts an object to its JSON representation.
|
public static <T extends JsonSerializable> java.lang.String serialize(T instance)
This is only usable for classes that have the JsonSerializable
marker interface,
indicating that the SDK knows how to serialize them.
T
- class of the object being serializedinstance
- the instance to serializepublic static <T extends JsonSerializable> T deserialize(java.lang.String json, java.lang.Class<T> objectClass) throws SerializationException
This is only usable for classes that have the JsonSerializable
marker interface,
indicating that the SDK knows how to serialize them.
The current implementation is limited in its ability to handle generic types. Currently, the only
such type defined by the SDKs is EvaluationDetail
. You can serialize
any EvaluationDetail<T>
instance and it will represent the T
value correctly, but
when deserializing, you will always get EvaluationDetail<LDValue>
.
T
- class of the object being deserializedjson
- the object's JSON encoding as a stringobjectClass
- class of the object being deserializedSerializationException
- if the JSON encoding was invalid