Class ObjectSerializer

java.lang.Object
com.developer.nefarious.zjoule.plugin.memory.utils.ObjectSerializer
All Implemented Interfaces:
IObjectSerializer

public class ObjectSerializer extends Object implements 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 Details

    • ObjectSerializer

      public ObjectSerializer()
  • Method Details

    • getInstance

      public static ObjectSerializer getInstance()
      Retrieves the singleton instance of ObjectSerializer.

      If the instance has not been initialized, it creates a new one.

      Returns:
      the singleton instance of ObjectSerializer.
    • deserialize

      public <T> T deserialize(String jsonString, Class<T> clazz)
      Deserializes a JSON string into an object of the specified class type.
      Specified by:
      deserialize in interface IObjectSerializer
      Type Parameters:
      T - the type of the object to deserialize.
      Parameters:
      jsonString - the JSON string to deserialize.
      clazz - the Class of the object to deserialize.
      Returns:
      the deserialized object of type T.
    • serialize

      public String serialize(Object object)
      Serializes an object into a JSON string.
      Specified by:
      serialize in interface IObjectSerializer
      Parameters:
      object - the object to serialize.
      Returns:
      the serialized JSON string.