Class ObjectSerializer
java.lang.Object
com.developer.nefarious.zjoule.plugin.memory.utils.ObjectSerializer
- All Implemented Interfaces:
IObjectSerializer
Singleton implementation of
IObjectSerializer
that provides methods
for serializing objects to JSON and deserializing JSON strings into objects.
This class uses the Google Gson library for JSON processing and ensures thread safety for singleton instance retrieval.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription<T> T
deserialize
(String jsonString, Class<T> clazz) Deserializes a JSON string into an object of the specified class type.static ObjectSerializer
Retrieves the singleton instance ofObjectSerializer
.Serializes an object into a JSON string.
-
Constructor Details
-
ObjectSerializer
public ObjectSerializer()
-
-
Method Details
-
getInstance
Retrieves the singleton instance ofObjectSerializer
.If the instance has not been initialized, it creates a new one.
- Returns:
- the singleton instance of
ObjectSerializer
.
-
deserialize
Deserializes a JSON string into an object of the specified class type.- Specified by:
deserialize
in interfaceIObjectSerializer
- Type Parameters:
T
- the type of the object to deserialize.- Parameters:
jsonString
- the JSON string to deserialize.clazz
- theClass
of the object to deserialize.- Returns:
- the deserialized object of type
T
.
-
serialize
Serializes an object into a JSON string.- Specified by:
serialize
in interfaceIObjectSerializer
- Parameters:
object
- the object to serialize.- Returns:
- the serialized JSON string.
-